Assembly Language Display Project: What code should be written in order to displ
ID: 3876050 • Letter: A
Question
Assembly Language Display Project: What code should be written in order to display this subtraction equation:
4 - 9 = -5
in command prompt?
PLEASE NOTE:
We are working in 32-bit and haven't been taught .data yet. I'll include a picture of an example of coding we've been given to learn so far. Thank you in advance!
Explanation / Answer
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
.model small
.data
a db 0AH
b db 04H
.code
mov ax, @data ; Initialize data section
mov ds, ax
mov al, a ; Load number1 in al
mov bl, b ; Load number2 in bl
sub al, bl ; subtract numbers and result in al
mov ch, 02h ; Count of digits to be displayed
mov cl, 04h ; Count to roll by 4 bits
mov bh, al ; Result in reg bh
l2: rol bh, cl ; roll bl so that msb comes to lsb
mov dl, bh ; load dl with data to be displayed
and dl, 0fH ; get only lsb
cmp dl, 09 ; check if digit is 0-9 or letter A-F
jbe l4
add dl, 07 ;
l4: add dl, 30H
mov ah, 02 ;
int 21H
dec ch ;
jnz l2
mov ah, 4cH ;
int 21H
end
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
.model small
.data
a db 0AH
b db 04H
.code
mov ax, @data ; Initialize data section
mov ds, ax
mov al, a ; Load number1 in al
mov bl, b ; Load number2 in bl
sub al, bl ; subtract numbers and result in al
mov ch, 02h ; Count of digits to be displayed
mov cl, 04h ; Count to roll by 4 bits
mov bh, al ; Result in reg bh
l2: rol bh, cl ; roll bl so that msb comes to lsb
mov dl, bh ; load dl with data to be displayed
and dl, 0fH ; get only lsb
cmp dl, 09 ; check if digit is 0-9 or letter A-F
jbe l4
add dl, 07 ;
l4: add dl, 30H
mov ah, 02 ;
int 21H
dec ch ;
jnz l2
mov ah, 4cH ;
int 21H
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.