Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3. ;
  4.  
  5. ; file: toupper.asm
  6.  
  7. ;
  8.  
  9. ; This program converts lowercase characters
  10.  
  11. ; to corresponding uppercase.
  12.  
  13. ;
  14.  
  15. ; Input: A string entered on the keyboard, terminated
  16.  
  17. ;        with the carriage return character.
  18.  
  19. ;
  20.  
  21. ; Output: Prints the string in uppercase.
  22.  
  23. ;
  24.  
  25. ; Author: Caiden Robinson
  26.  
  27. ; Date: 4/18/11
  28.  
  29. ;
  30.  
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32.  
  33.  
  34.  
  35. %include "asm_io.inc"
  36.  
  37.  
  38.  
  39. LF  equ 0Ah
  40.  
  41.  
  42.  
  43. segment .data
  44.  
  45. ;
  46.  
  47. ; initialized data is put in the data segment here
  48.  
  49. ;
  50.  
  51.  
  52.  
  53. name_prompt    DB  'Please type your name: ',0
  54.  
  55. rep_prompt DB 'Do you want to quit (Y/N) :',0
  56.  
  57. out_msg        DB  'Your name in capitals is: ',0
  58.  
  59.  
  60.  
  61. ;Ans_Y DB 'Y'
  62.  
  63. ;Ans_N DB 'N'
  64.  
  65.  
  66.  
  67. segment .bss
  68.  
  69. ;
  70.  
  71. ; uninitialized data is put in the bss segment
  72.  
  73. ;
  74.  
  75.  
  76.  
  77. in_name    resb  30
  78.  
  79. in_ans resb 1
  80.  
  81.  
  82.  
  83. segment .text
  84.  
  85.         global  asm_main
  86.  
  87. asm_main:
  88.  
  89.         enter   0,0            ; setup routine
  90.  
  91.         pusha
  92.  
  93.  
  94.  
  95.     begin:
  96.  
  97.  
  98.  
  99.         mov  eax, name_prompt  ; print prompt
  100.  
  101.     call print_string
  102.  
  103.     mov  ebx, in_name
  104.  
  105. rd_loop:
  106.  
  107.         call read_char         ; read in the string
  108.  
  109.     mov  [ebx], al
  110.  
  111.         inc  ebx
  112.  
  113.     cmp  al, LF
  114.  
  115.         jne  rd_loop
  116.  
  117.  
  118.  
  119.     dec  ebx               ; put in null terminator
  120.  
  121.     mov  byte [ebx], 0
  122.  
  123.         call print_nl          ; print output msg
  124.  
  125.         mov  eax, out_msg
  126.  
  127.     call print_string
  128.  
  129.  
  130.  
  131.         mov  ebx, in_name      ; EBX := address of in_name
  132.  
  133. process_char:
  134.  
  135.         mov     AL,[EBX]       ; move the char to AL
  136.  
  137.         cmp     AL,0           ; if it is the NULL character
  138.  
  139.         je      done           ;  conversion done
  140.  
  141.         cmp     AL,'a'         ; if (char < 'a')
  142.  
  143.         jl      not_lower_case ; not a lowercase letter
  144.  
  145.         cmp     AL,'z'         ; if (char > 'z')
  146.  
  147.         jg      not_lower_case ; not a lowercase letter
  148.  
  149. lower_case:
  150.  
  151.         add     AL,'A'-'a'     ; convert to uppercase
  152.  
  153. not_lower_case:
  154.  
  155.     call    print_char
  156.  
  157.         inc     EBX            ; BX points to next char.
  158.  
  159.         jmp     process_char   ; go back to process next char.
  160.  
  161.  
  162.  
  163. done:                        
  164.  
  165.         call print_nl
  166.  
  167.         call print_nl
  168.  
  169.  
  170.  
  171. ;;This is a loop that asks the user if
  172.  
  173. ;;they would like to repeat the program
  174.  
  175.  
  176.  
  177. Rep_rd_loop:
  178.  
  179.     mov eax, rep_prompt
  180.  
  181.     call print_string
  182.  
  183.     mov ebx, in_ans
  184.  
  185.  
  186.  
  187.     call read_char
  188.  
  189.     mov [ebx], al
  190.  
  191.     call read_char
  192.  
  193.     call print_nl
  194.  
  195.  
  196.  
  197.     mov al, [ebx]
  198.  
  199.     cmp AL, 'y'
  200.  
  201.     je done2
  202.  
  203.     cmp AL, 'Y'
  204.  
  205.     je done2
  206.  
  207.     cmp AL, 'n'
  208.  
  209.     je begin
  210.  
  211.     cmp AL, 'N'
  212.  
  213.     je begin
  214.  
  215.     jmp Rep_rd_loop
  216.  
  217.  
  218.  
  219. done2:
  220.  
  221.  
  222.  
  223.         popa
  224.  
  225. ;;;;;;;;;;;;;;;
  226.  
  227.  
  228.  
  229. ;;;;;;;;;;;;;;;
  230.  
  231.         mov     eax, 0         ; return back to C
  232.  
  233.         leave                    
  234.  
  235.         ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement