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.
.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
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
---------------------------------------------------
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 .
Web & Social Media Analytics Previous Year Question Paper.pdf
1) (a) Write a code fragment which adds the 32-bit contents of $8100.pdf
1. 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.
.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
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
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
4. 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
5. 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
7. 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