Advertisement
AVONnadozie

Tourist Translation ASM

Mar 27th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TITLE 'TOURIST TRANSLATION'
  2. .MODEL SMALL
  3. .STACK
  4. .DATA
  5.     CRLF DB 0DH, 0AH, '$'
  6.     KEY DB 28 DUP(?)
  7.     N DB ?
  8. .CODE
  9. START:  MOV AX, @DATA
  10.         MOV DS, AX
  11.        
  12.         LEA SI, KEY
  13.         CALL READER         ;Reads first line to memory starting from KEY
  14.        
  15.         LEA SI, KEY
  16.         CALL CHAR2INTR      ;Converts characters before white-space to decimal
  17.         MOV CX, AX          ;Moves number to CX for loop
  18.        
  19. .LOOP1: LEA SI, N
  20.         CALL READER         ;Reads next line into memory starting from N
  21. .LOOP2: XOR BX, BX          ;Clears BX
  22.         MOV BL, [SI]        ;Loads value from memory
  23.         CMP BL, '$'         ;checks if it is END-OF-LINE indicator
  24.         JE BRK
  25.        
  26.         MOV BL, [SI]
  27.         CMP BL, '_'
  28.         JE IF_
  29.                             ;Checking if it is UPPERCASE
  30.         MOV BL, [SI]
  31.         CMP BL, 'A'
  32.         JNGE CONTINUE1
  33.         SUB BL, 'A'         ;Gets alphabet's index
  34.         CMP BL, 25
  35.         JNG BIG_LETTER
  36.                             ;Checking if it is LOWERCASE       
  37.         MOV BL, [SI]
  38.         CMP BL, 'a'
  39.         JNGE CONTINUE1
  40.         SUB BL, 'a'
  41.         CMP BL, 25
  42.         JNG SMALL_LETTER
  43. CONTINUE1:
  44.         INC SI
  45.         JMP .LOOP2     
  46. BRK:    MOV AH, 09H
  47.         LEA DX, N
  48.         INT 21H
  49.         LEA DX, CRLF
  50.         INT 21H
  51.         LOOP .LOOP1    
  52.        
  53.         MOV AH, 4CH
  54.         INT 21H
  55.  
  56. IF_:    MOV BL, ' '
  57.         MOV [SI], BL        ;Replaces '_' with ' '
  58.         JMP CONTINUE1
  59.  
  60. SMALL_LETTER:
  61.         LEA DI, KEY+2
  62.         MOV BL, [DI + BX]   ;Gets character(translation) at the index
  63.         MOV [SI], BL        ;Replaces byteland chracter with it's translation
  64.         JMP CONTINUE1
  65.  
  66. BIG_LETTER:
  67.         LEA DI, KEY+2
  68.         MOV BL, [DI + BX]   ;Gets character(translation) at the index
  69.         SUB BL, 32          ;Substracts 32 get character's UPPERCASE
  70.         MOV [SI], BL        ;Replaces byteland chracter with it's translation
  71.         JMP CONTINUE1
  72.  
  73. ;Subroutine READER 
  74. READER PROC
  75.         PUSH AX
  76.         PUSH SI
  77.         PUSHF
  78.         MOV AX, 0000H
  79.        
  80. RLOOP:  MOV AH, 01H
  81.         INT 21H             ;Receives input
  82.         CMP AL, 13          ;Checks if it is CARRIAGE-RETURN
  83.         JE XRLOOP           ;Exits loop if the character is CARRIAGE-RETURN
  84.         CMP AL, 10          ;Checks if it is LINE-FEED
  85.         JE XRLOOP           ;Exits loop if the character is LINE-FEED  
  86.         CMP AL, 8           ;Checks if it is BACK-SPACE
  87.         JE BKSPC
  88.         MOV [SI], AL        ;If not carrige return, moves input to current address
  89.         INC SI              ;Moves pointer to the next address
  90. CONTINUE:
  91.         JMP RLOOP           ;Repeats the above process starting from RLOOP:
  92. XRLOOP:                     ;If input is CARRIAGE-RETURN
  93.         MOV AL, '$'        
  94.         MOV [SI], AL        ;Places 'end of data' mark '$'
  95.         POPF
  96.         POP SI
  97.         POP AX
  98.         RET
  99. BKSPC:  DEC SI
  100.         JMP CONTINUE
  101. READER ENDP
  102. ;End of Subroutine READER
  103.  
  104. ;Subroutine CHAR2INTR
  105. CHAR2INTR PROC
  106.             PUSH BX
  107.             PUSH CX
  108.             PUSH DX
  109.             PUSH SI
  110.             PUSHF
  111.            
  112.             MOV AX, 0000H
  113.             MOV CX, 0000H
  114. CLOOP1:     MOV AX, [SI]            ;Loads character currently pointed to into AX
  115.             CMP AL, '9'
  116.             JNLE XCLOOP1            ;Exits loop if character is not less or equal to '9'
  117.             CMP AL, '0'
  118.             JNGE XCLOOP1            ;Exits loop if character is not greater or equal to '0'
  119.             INC CL                  ;Else, Keeps count of the number of characters being processed
  120.             INC SI                  ;Moves pointer to the next character
  121.             SUB AL, 30H             ;Converts character to digit
  122.             PUSH AX                 ;Pushes digit to stack
  123.             JMP CLOOP1              ;continues loop
  124.  
  125. XCLOOP1:    MOV BX, 0001H
  126.             MOV DX, 0000H
  127. CLOOP2:     CMP CL, 0               ;Checks number of characters processed
  128.             JE XCLOOP2              ;Exits loop if no character was processed i.e CL = 0
  129.             POP AX                  ;Else, pops digit from stack to AX
  130.             MUL BL                  ;Multiplies digit with it's PLACEMENT-VALUE. RECALL: unit = 1, tens = 10, hundreds = 100 ...
  131.             ADD DX, AX              ;Adds (digit * PLACEMENT-VALUE)s together. RECALL: 234 = (4 * 1) + (3 * 10) + (2 * 100) where 1,10,100 represent their PLACEMENT-VALUES
  132.             MOV AX, 10             
  133.             MUL BL                  ;Multiplies current PLACEMENT-VALUE by 10 to advance to the next PLACEMENT-VALUE.
  134.             XCHG AX, BX             ;Puts result from multiplication back to BX
  135.             DEC CX                  ;Reduces count
  136.             JMP CLOOP2              ;Loop continues
  137.            
  138. XCLOOP2:    MOV AX, DX              ;Moves converted value to AX
  139.            
  140.             POPF
  141.             POP SI
  142.             POP DX
  143.             POP CX
  144.             POP BX
  145.             RET
  146. CHAR2INTR ENDP
  147. ;End of Subroutine CHAR2INTR
  148.  
  149. END START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement