Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TITLE 'TOURIST TRANSLATION'
- .MODEL SMALL
- .STACK
- .DATA
- CRLF DB 0DH, 0AH, '$'
- KEY DB 28 DUP(?)
- N DB ?
- .CODE
- START: MOV AX, @DATA
- MOV DS, AX
- LEA SI, KEY
- CALL READER ;Reads first line to memory starting from KEY
- LEA SI, KEY
- CALL CHAR2INTR ;Converts characters before white-space to decimal
- MOV CX, AX ;Moves number to CX for loop
- .LOOP1: LEA SI, N
- CALL READER ;Reads next line into memory starting from N
- .LOOP2: XOR BX, BX ;Clears BX
- MOV BL, [SI] ;Loads value from memory
- CMP BL, '$' ;checks if it is END-OF-LINE indicator
- JE BRK
- MOV BL, [SI]
- CMP BL, '_'
- JE IF_
- ;Checking if it is UPPERCASE
- MOV BL, [SI]
- CMP BL, 'A'
- JNGE CONTINUE1
- SUB BL, 'A' ;Gets alphabet's index
- CMP BL, 25
- JNG BIG_LETTER
- ;Checking if it is LOWERCASE
- MOV BL, [SI]
- CMP BL, 'a'
- JNGE CONTINUE1
- SUB BL, 'a'
- CMP BL, 25
- JNG SMALL_LETTER
- CONTINUE1:
- INC SI
- JMP .LOOP2
- BRK: MOV AH, 09H
- LEA DX, N
- INT 21H
- LEA DX, CRLF
- INT 21H
- LOOP .LOOP1
- MOV AH, 4CH
- INT 21H
- IF_: MOV BL, ' '
- MOV [SI], BL ;Replaces '_' with ' '
- JMP CONTINUE1
- SMALL_LETTER:
- LEA DI, KEY+2
- MOV BL, [DI + BX] ;Gets character(translation) at the index
- MOV [SI], BL ;Replaces byteland chracter with it's translation
- JMP CONTINUE1
- BIG_LETTER:
- LEA DI, KEY+2
- MOV BL, [DI + BX] ;Gets character(translation) at the index
- SUB BL, 32 ;Substracts 32 get character's UPPERCASE
- MOV [SI], BL ;Replaces byteland chracter with it's translation
- JMP CONTINUE1
- ;Subroutine READER
- READER PROC
- PUSH AX
- PUSH SI
- PUSHF
- MOV AX, 0000H
- RLOOP: MOV AH, 01H
- INT 21H ;Receives input
- CMP AL, 13 ;Checks if it is CARRIAGE-RETURN
- JE XRLOOP ;Exits loop if the character is CARRIAGE-RETURN
- CMP AL, 10 ;Checks if it is LINE-FEED
- JE XRLOOP ;Exits loop if the character is LINE-FEED
- CMP AL, 8 ;Checks if it is BACK-SPACE
- JE BKSPC
- MOV [SI], AL ;If not carrige return, moves input to current address
- INC SI ;Moves pointer to the next address
- CONTINUE:
- JMP RLOOP ;Repeats the above process starting from RLOOP:
- XRLOOP: ;If input is CARRIAGE-RETURN
- MOV AL, '$'
- MOV [SI], AL ;Places 'end of data' mark '$'
- POPF
- POP SI
- POP AX
- RET
- BKSPC: DEC SI
- JMP CONTINUE
- READER ENDP
- ;End of Subroutine READER
- ;Subroutine CHAR2INTR
- CHAR2INTR PROC
- PUSH BX
- PUSH CX
- PUSH DX
- PUSH SI
- PUSHF
- MOV AX, 0000H
- MOV CX, 0000H
- CLOOP1: MOV AX, [SI] ;Loads character currently pointed to into AX
- CMP AL, '9'
- JNLE XCLOOP1 ;Exits loop if character is not less or equal to '9'
- CMP AL, '0'
- JNGE XCLOOP1 ;Exits loop if character is not greater or equal to '0'
- INC CL ;Else, Keeps count of the number of characters being processed
- INC SI ;Moves pointer to the next character
- SUB AL, 30H ;Converts character to digit
- PUSH AX ;Pushes digit to stack
- JMP CLOOP1 ;continues loop
- XCLOOP1: MOV BX, 0001H
- MOV DX, 0000H
- CLOOP2: CMP CL, 0 ;Checks number of characters processed
- JE XCLOOP2 ;Exits loop if no character was processed i.e CL = 0
- POP AX ;Else, pops digit from stack to AX
- MUL BL ;Multiplies digit with it's PLACEMENT-VALUE. RECALL: unit = 1, tens = 10, hundreds = 100 ...
- 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
- MOV AX, 10
- MUL BL ;Multiplies current PLACEMENT-VALUE by 10 to advance to the next PLACEMENT-VALUE.
- XCHG AX, BX ;Puts result from multiplication back to BX
- DEC CX ;Reduces count
- JMP CLOOP2 ;Loop continues
- XCLOOP2: MOV AX, DX ;Moves converted value to AX
- POPF
- POP SI
- POP DX
- POP CX
- POP BX
- RET
- CHAR2INTR ENDP
- ;End of Subroutine CHAR2INTR
- END START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement