Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;::::::::::::::::::::::::::::::::::::::::::::::::::::
- ;
- ; file: toupper.asm
- ;
- ; This program converts lowercase characters
- ; to corresponding uppercase.
- ;
- ; Input: A string entered on the keyboard, terminated
- ; with the carriage return character.
- ;
- ; Output: Prints the string in uppercase.
- ;
- ; Author: Caiden Robinson
- ; Date: 4/18/11
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- %include "asm_io.inc"
- LF equ 0Ah
- segment .data
- ;
- ; initialized data is put in the data segment here
- ;
- name_prompt DB 'Please type your name: ',0
- rep_prompt DB 'Do you want to quit (Y/N) :',0
- out_msg DB 'Your name in capitals is: ',0
- ;Ans_Y DB 'Y'
- ;Ans_N DB 'N'
- segment .bss
- ;
- ; uninitialized data is put in the bss segment
- ;
- in_name resb 30
- in_ans resb 1
- segment .text
- global asm_main
- asm_main:
- enter 0,0 ; setup routine
- pusha
- begin:
- mov eax, name_prompt ; print prompt
- call print_string
- mov ebx, in_name
- rd_loop:
- call read_char ; read in the string
- mov [ebx], al
- inc ebx
- cmp al, LF
- jne rd_loop
- dec ebx ; put in null terminator
- mov byte [ebx], 0
- call print_nl ; print output msg
- mov eax, out_msg
- call print_string
- mov ebx, in_name ; EBX := address of in_name
- process_char:
- mov AL,[EBX] ; move the char to AL
- cmp AL,0 ; if it is the NULL character
- je done ; conversion done
- cmp AL,'a' ; if (char < 'a')
- jl not_lower_case ; not a lowercase letter
- cmp AL,'z' ; if (char > 'z')
- jg not_lower_case ; not a lowercase letter
- lower_case:
- add AL,'A'-'a' ; convert to uppercase
- not_lower_case:
- call print_char
- inc EBX ; BX points to next char.
- jmp process_char ; go back to process next char.
- done:
- call print_nl
- call print_nl
- ;;This is a loop that asks the user if
- ;;they would like to repeat the program
- Rep_rd_loop:
- mov eax, rep_prompt
- call print_string
- mov ebx, in_ans
- call read_char
- mov [ebx], al
- call read_char
- call print_nl
- mov al, [ebx]
- cmp AL, 'y'
- je done2
- cmp AL, 'Y'
- je done2
- cmp AL, 'n'
- je begin
- cmp AL, 'N'
- je begin
- jmp Rep_rd_loop
- done2:
- popa
- ;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;
- mov eax, 0 ; return back to C
- leave
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement