1 a Write a code fragment which adds the 32bit contents of 8
1) (a) Write a code fragment which adds the 32-bit contents of $8100 (LSB) - 8103 (MSB) to $8104 - $8107 and stores it to $8100 - $8103. (b) Write a similar code fragment, which adds the 8-digit BCD contents of $8200 - $8203 to $8204 - $8207 and stores it to $8200 - $8203. Using 68HC11 Assembly Instruction Set.
Solution
Step I : Initialize the data segment.
Step II : Load the LSB of first number into AX register.
Step III : Load the MSB of first number into BX register.
Step IV : Load the LSB of the second number into CX register.
Step V : Load the MSB of the second number into DX register.
Step VI : Add the LSBs of two number.
Step VII : Add the MSBs of two numbers along with carry.
Step VIII : Display the result.
Step IX : Stop.
<div id=\"inner-editor\"><br class=\"Apple-interchange-newline\"> .model small <br> .data <br> op1 dd 12345678h <br> op2 dd 11111111h Corel - 10 <br> ans dd ? <br> .code <br> mov ax, @data <br> mov ds, ax <br> mov ax, word ptr op1 ; lsb of number1 in ax <br> mov bx, word ptr op1+2 ; msb of number1 in bx <br> mov cx, word ptr op2 ; lsb of number2 in cx <br> mov dx, word ptr op2+2 ; msb of number1 in dx <br> add ax, cx ; add msb + msb + carry <br> mov word ptr ans, ax ; lsb answer <br> mov word ptr ans+2, bx ; msb answer <br> mov bx, word ptr ans+2 ; Result in reg bx <br> mov dh, 2 <br> l1: mov ch, 04h ; Count of digits to be displayed <br> mov cl, 04h ; Count to roll by 4 bits <br> l2: rol bx, cl ; roll bl so that msb comes to lsb <br> mov dl, bl ; load dl with data to be displayed <br> and dl, 0fH ; get only lsb <br> cmp dl, 09 ; check if digit is 0-9 or letter A-F <br> jbe l4 <br> add dl, 07 ; if letter add 37H else only add 30H <br> l4: add dl, 30H <br> mov ah, 02 ; INT 21H (Display character) <br> int 21H <br> dec ch ; Decrement Count <br> jnz l2 <br> dec dh <br> cmp dh, 0 <br> mov bx, word ptr ans ; display lsb of answer <br> jnz l1 <br> mov ah, 4ch ; Terminate Program <br> int 21h <br> end <br><br></div>
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
.model small
.data
op1 dd 12345678h
op2 dd 11111111h Corel - 10
ans dd ?
.code
mov ax, @data
mov ds, ax
mov ax, word ptr op1 ; lsb of number1 in ax
mov bx, word ptr op1+2 ; msb of number1 in bx
mov cx, word ptr op2 ; lsb of number2 in cx
mov dx, word ptr op2+2 ; msb of number1 in dx
add ax, cx ; add msb + msb + carry
mov word ptr ans, ax ; lsb answer
mov word ptr ans+2, bx ; msb answer
mov bx, word ptr ans+2 ; Result in reg bx
mov dh, 2
l1: mov ch, 04h ; Count of digits to be displayed
mov cl, 04h ; Count to roll by 4 bits
l2: rol bx, cl ; roll bl so that msb comes to lsb
mov dl, bl ; 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 ; if letter add 37H else only add 30H
l4: add dl, 30H
mov ah, 02 ; INT 21H (Display character)
int 21H
dec ch ; Decrement Count
jnz l2
dec dh
cmp dh, 0
mov bx, word ptr ans ; display lsb of answer
jnz l1
mov ah, 4ch ; Terminate Program
int 21h
---------------------------------------------------
Step 1 : Initialize the data segment.
Step 2 : Get the first number in AL register.
Step 3 : Get the second number in BL register.
Step 4 : Add the two numbers.
Step 5 : Display the result.
Step 6 : Stop
.model small
.data
a db 09H
b db 02H
.code
mov ax, @data ; Initialize data section
mov ds, ax
mov al, a ; Load number1 in al
mov bl, b ; Load number2 in bl
add al, bl ; add 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 ; if letter add 37H else only add 30H
l4: add dl, 30H
mov ah, 02 ; Function 2 under INT 21H (Display character)
int 21H
dec ch ; Decrement Count
jnz l2
mov ah, 4CH ; Terminate Program
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 28 29 30 31 32 33 34 35 36 37 38 | .model small .data op1 dd 12345678h op2 dd 11111111h Corel - 10 ans dd ? .code mov ax, @data mov ds, ax mov ax, word ptr op1 ; lsb of number1 in ax mov bx, word ptr op1+2 ; msb of number1 in bx mov cx, word ptr op2 ; lsb of number2 in cx mov dx, word ptr op2+2 ; msb of number1 in dx add ax, cx ; add msb + msb + carry mov word ptr ans, ax ; lsb answer mov word ptr ans+2, bx ; msb answer mov bx, word ptr ans+2 ; Result in reg bx mov dh, 2 l1: mov ch, 04h ; Count of digits to be displayed mov cl, 04h ; Count to roll by 4 bits l2: rol bx, cl ; roll bl so that msb comes to lsb mov dl, bl ; 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 ; if letter add 37H else only add 30H l4: add dl, 30H mov ah, 02 ; INT 21H (Display character) int 21H dec ch ; Decrement Count jnz l2 dec dh cmp dh, 0 mov bx, word ptr ans ; display lsb of answer jnz l1 mov ah, 4ch ; Terminate Program int 21h |




