INP
STA x
INP
STA y
LDA x
SUB y
BRP xmax
LDA x
OUT
HLT
xmax LDA y
OUT
HLT
x DAT
y DAT
small = input
big = input
while big > 0
big = big - small
answer = 0
if big > 0
answer = answer + 1
continue
if big < 0
print answer
endwhile
1. a. 64
b. Immediate addressing takes the value of the operand as the value to add. Direct addressing takes the value stored at the address of the operand. Indirect addressing goes to the address of the operand, follows its address to another memory location, and adds that value stored.
If the operand is 10110:
Immediate: The value to add is 10110 (22)
Direct: The value to add is in memory address 10110
Indirect: In register (or memory address) 10110 you'll find the address of the data to add
2.
LDA num1
ADD num2
STA num3
HLT
num1 DAT
num2 DAT
num3 DAT
3.
in LDA numvals
ADD increment
STA numvals
INP
STA x
ADD total
STA total
LDA x
BRZ stop
BRP in
stop LDA numvals
SUB increment
OUT
LDA total
OUT
HLT
increment DAT 1
numvals DAT 0
total DAT 0
x DAT
hello INP
STA x
ADD one
SUB fifty
STA y
BRZ hello
BRP no
no LDA x
ADD y
STA x
BRA shush
shush LDA x
OUT
HLT
x DAT
y DAT
one DAT 1
fifty DAT 50