-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.DisplayInReverse.asm
88 lines (66 loc) · 3.81 KB
/
10.DisplayInReverse.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
TITLE DisplayInReverse
;Program Desctiption: This program receives a four digit number and returns the number reversed
;Author: Liul Alemayehu
.MODEL SMALL ; com program, Memory Descriptor (Tiny | Small | Medium | Large)
.STACK 100 ; stack size
.DATA ; Beginning of data segment where data is stored
msg db "Enter a 4-digit number: $" ; Declare variable msg and assigned it a value ($ used to indicate end of string)
newline db 13,10,'$' ; Creates newline
reversedMsg db "The number reversed:- $" ; Reversed message
.CODE ; Beginning of code segment
;main PROC
; Start
MOV Ax,@DATA ; Moving address of data (data segment) to Ax register
MOV Ds,Ax ; Initializing of Data segment register (Ds) from Accumilator register (Ax)
; Prompt
LEA Dx,msg ; Loading the effective address of our msg to the Data register (Dx)
MOV Ah,09 ; Print from data
INT 21h ; Does it!
; Read number
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
PUSH Ax ; Pushes value to stack
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
PUSH Ax ; Pushes value to stack
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
PUSH Ax ; Pushes value to stack
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
PUSH Ax ; Pushes value to stack
; Check if ENTER is pressed
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
CMP Al,13 ; Compare the input in the Accumilator registor to the ASCII value of the ENTER key (13)
JE Enter ; Jumps to 'Enter' label if the CMP is equal
JMP Exit ; Jumps to 'Exit' label otherwise
; Enter Pressed
Enter:
; Print reversed number
; Newline
LEA Dx,newline
MOV Ah,09h
INT 21h
; Print reversed message
LEA Dx,reversedMsg ; Loading the effective address of our message to the Data register (Dx)
MOV Ah,09 ; Print from data
INT 21h ; Does it!
; Print value
POP Dx ; Pops value from stack
MOV Ah,02 ; Prints it
INT 21h
POP Dx ; Pops value from stack
MOV Ah,02 ; Prints it
INT 21h
POP Dx ; Pops value from stack
MOV Ah,02 ; Prints it
INT 21h
POP Dx ; Pops value from stack
MOV Ah,02 ; Prints it
INT 21h
Exit:
MOV Ah,4Ch ; Exit
INT 21h ; Does it!
;main ENDP
END main