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

Assume we have CPU instructions that look like this: - load register, address -

ID: 3880427 • Letter: A

Question

Assume we have CPU instructions that look like this:

- load register, address

- save register, address

Where the instruction load saves the data pointed to by the address into the register, and the instruction save writes the data from the register into the location pointed to by address.

Assume at address 52 is the beginning of a string “ABC” and at address 1 is the printer.

Write pseudo-C code that uses the above CPU instructions to print the string to the printer (move each byte to address 1). You can use variables in place of register and address. You can assume the string ends with a NULL.

Explanation / Answer

/*assuming the registers to be of type string variable*/

char AD52[]="ABC";

char AD1[4];

char reg[4];

/*loads the content of address 52 into working register*/

str.copy(reg,AD52);

AD52=NULL /*removes the content of AD52 and makes it null */

/*copies the content of working register into AD1 one bit at a time*/

for(int i=0;i<4;i++)

AD1[i]=reg[i];