Assume we have CPU instructions that look like this: load register, address
save register, address
Where the instruction load copies the data pointed to by the
address into the register, and the instruction save copies the data
from the register into the location pointed to by address. Assume
“register” can be the values R0 and R1, where each “R#” is the name
of a single register that can store a single byte. Assume the
“address” is an integer constant number.
Assume at address 52 is the beginning of a string “ABC”. Assume at address 1 is the printer.
Using only the above two instructions, write code that sends each byte of the string to the printer.
Address 52 is the beginning of a string "ABC". Since each ASCII character is one byte, we can assume than address 52 and two consecutive addresses stores "A", "B","C", i.e. address 52 stores "A", address 53 stores "B", address 54 stores "C".
So code to send each byte of the string to the printer,
load R0, 52 (Copies data at address 52 to register 0)
save R0, 1 (Copies data from the register 0 to the printer at address 1)
load R1, 53 (Copies data at address 53 to register 1)
save R1, 1 (Copies data from the register 1 to the printer at address 1)
load R2, 54 (Copies data at address 54 to register 2)
save R2, 1 (Copies data from the register 2 to the printer at address 1)
Get Answers For Free
Most questions answered within 1 hours.