-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverse.asm
More file actions
63 lines (54 loc) · 802 Bytes
/
Reverse.asm
File metadata and controls
63 lines (54 loc) · 802 Bytes
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
.model small
.stack 100h
.data
msg1 db 'Enter number: $'
msg2 db 13,10, 'Reversed: $'
input db 5, 0, 5 dup(0)
.code
main:
mov ax, @data
mov ds, ax
lea dx, msg1
mov ah, 9
int 21h
lea dx, input
mov ah, 0Ah
int 21h
lea dx, msg2
mov ah, 9
int 21h
lea si, input+2
call strToNum
mov bx, 10
reverse_loop:
xor dx, dx
div bx
push dx
test ax, ax
jnz reverse_loop
print_loop:
pop dx
add dl, '0'
mov ah, 2
int 21h
cmp sp, 0FFFEh
jne print_loop
mov ah, 4Ch
int 21h
strToNum:
xor ax, ax
xor bx, bx
next_digit:
mov bl, [si]
cmp bl, 13
je done
sub bl, '0'
mov cx, ax
mov ax, 10
mul cx
add ax, bx
inc si
jmp next_digit
done:
ret
end main