Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program at address 0 times 100 in PIC18F assembly language to add two 32

ID: 3832543 • Letter: W

Question

Write a program at address 0 times 100 in PIC18F assembly language to add two 32-bit packed BCD numbers. BCD number 1 is stored in data registers starting from 0 times 20 through 0 times 23, with the least significant digit at register 0 times 23 and the most significant digit at 0 times 20. BCD number 2 is stored in data registers starting from 0 times 30 through 0 times 33, with the least significant digit at 0 times 33 and the most significant digit at 0 times 30. Store the result as packed BCD digits in 0 times 20 through 0 times 23.

Explanation / Answer

.model small
.stack
data segment
op1 dd 12345678h   
op2 dd 11111111h
ans dd ?
ends data
code segment
assume cs:code, ds:data
start :
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 ; subtract lsb + lsb
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
code ends
end start
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote