Write a Pep/9 assembler program that multiplies a number by another by repeated
ID: 3815142 • Letter: W
Question
Write a Pep/9 assembler program that multiplies a number by another by repeated addition. For example, to multiply 0x21 by 0x07, we add 0x21 + 0x21 + 0x21 + 0x21 + 0x21 + 0x21 + 0x21, seven times. In your program, multiply 0x61 by 0x0A. In general, multiplying two 8-bit numbers results in a 16-bit product. (Turn in a screenshot after the run. It should include the source code. Name it Lb3A-4). Write a Pep/9 assembler program that multiplies a number by another by repeated addition. For example, to multiply 0x21 by 0x07, we add 0x21 + 0x21 + 0x21 + 0x21 + 0x21 + 0x21 + 0x21, seven times. In your program, multiply 0x61 by 0x0A. In general, multiplying two 8-bit numbers results in a 16-bit product. (Turn in a screenshot after the run. It should include the source code. Name it Lb3A-4).Explanation / Answer
Here is the source code:
BR main
num1: .BLOCK 2 ;first number to be multiplied
num2: .BLOCK 2 ;second number to be multiplied
ans: .BLOCK 2 ;result of multiplication
i: .BLOCK 2 ;iterator to count thru the
max: .EQUATE 8
;obtain the two numbers to be multiplied
main: DECI num1,d
DECI num2,d
;output first part of feedback to user
DECO num1,d
STRO str1,d
DECO num2,d
STRO str2,d
;initialize i to 0
LDA 0x0000, i
STA i,d
;check if i < max and branch to "end" if i >= max
loop: LDX i,d
CPX max,i
BRGE end
;see if the LSB of num1 == 0
LDA num1,d
ANDA 0x0001,i
CPA 0x0001,i
;if LSB of num1 == 0, jump to next iteration
BRNE next
;if LSB of num1 == 1, update answer
LDA ans,d
ADDA num2,d
STA ans,d
;shift num1 right once
next: LDA num1,d
ASRA
STA num1,d
;shift num2 left once
LDA num2,d
ASLA
STA num2,d
;i++
LDX i,d
ADDX 0x0001,i
STX i,d
;repeat loop
BR loop
;output second part of feedback
end: DECO ans,d
STOP ;stop program execution
str1: .ASCII " * "
str2: .ASCII " = "
.END ;terminate program
BR main
num1: .BLOCK 2 ;first number to be multiplied
num2: .BLOCK 2 ;second number to be multiplied
ans: .BLOCK 2 ;result of multiplication
i: .BLOCK 2 ;iterator to count thru the
max: .EQUATE 8
;obtain the two numbers to be multiplied
main: DECI num1,d
DECI num2,d
;output first part of feedback to user
DECO num1,d
STRO str1,d
DECO num2,d
STRO str2,d
;initialize i to 0
LDA 0x0000, i
STA i,d
;check if i < max and branch to "end" if i >= max
loop: LDX i,d
CPX max,i
BRGE end
;see if the LSB of num1 == 0
LDA num1,d
ANDA 0x0001,i
CPA 0x0001,i
;if LSB of num1 == 0, jump to next iteration
BRNE next
;if LSB of num1 == 1, update answer
LDA ans,d
ADDA num2,d
STA ans,d
;shift num1 right once
next: LDA num1,d
ASRA
STA num1,d
;shift num2 left once
LDA num2,d
ASLA
STA num2,d
;i++
LDX i,d
ADDX 0x0001,i
STX i,d
;repeat loop
BR loop
;output second part of feedback
end: DECO ans,d
STOP ;stop program execution
str1: .ASCII " * "
str2: .ASCII " = "
.END ;terminate program
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.