Lab 8

5. Messages, Data Segment, Text Segment, Registers.
Length.asm has been successfully loaded. If an error occurs check that there is a carriage return on the last line, i.e. go to the end of the place line and press the enter key.

6. The null termimated strings "Length is" , "hello world" and "\n".

7. Address: [0x10000000] Contents: 0x00
First non-zero address: [0x10010000] Contents: 0x68
w: [0x10010006]
d: [0x1001000a]
Null: [0x1001000b]

8. Line 11 (this will depend on whether you type in all the commented lines or not).
lui: 3c
Address = [0x00400008]
ori $9, $0, 0 and then into the machine code: 0x34090000

9. 00400000, which is the starting address of the text segment. The instruction is la $t2, str.

11. Yes i.e. [0x00400000], i.e. the first line of code from the program.
Length = 11, which IS the correct answer.

N.B. Ensure you reload the code at this stage!!!!

12. The first line of code from the text segment has appeared in the messages window.
la $t2, str is translated into 2 instructions.
The instructions are "lui $1, 4097 [str]" and "ori $10, $1, 0 [str]"
[0x10010000] which is the value in $t2 after the two lines of pseudo-instructions have been executed.
13. $t1: 0x00000000

14. $t0 contains 0x68 if a lowercase h was used or 0x48 for 'H'.

15. No $t0 is not zero. Next instruction is "add $t1, $t1, 1"

16. $t1 is now 0x00000001.

17. $t2 holds the address of the current character being counted from the string. This is similar to the "index" variable that you might have in Java for keeping a record of which character in a string is being dealt with.
$t2 is now 0x10010001.

18. The instruction specified by the label nextCh is lb $t0, ($t2)
PC = 0x0040000c

19. $t2 is now 0x10010001 at Step 14 it was 0x10010000.
$t0 = $t2 is now 0x00000065.

20. The next instruction that will be executed is beqz $t0, strEnd
No the program does not make a conditional branch as the condition of $t0 being equal to zero is not meet.

21. $t1 = 0x00000002 and $t2 = 0x10010002, we have counted two characters. Note here that the address is actually the third character at this stage but we need to check if it's the null terminator before counting it.

22. The program does make a conditional jump as the value of $t0 is 0.
The address of the next instruction is [0x00400020]. The value of the PC register is 0x00400020.

23. $a0 = 0x1001000c, the contents at this address are "4c".
$a0 holds the address of a string to be outputted or a numerical value if a number is to be printed.

24. $v0 = 0x00000004. The register number is R2.
$v0 holds the system call codes from 1 to 10. Anytime a syscall command is executed the content of $v0 are checked to see what has to be done.
4 represents "print a string".

"Length is " has appeared in it.

25. It copies the values from $t0 into $a0.
$a0 is specified as this is the register that the system call looks in when it prints out data.

26. 1 is used to print an integer.
"Length is 11" has appeared in it.

27. Exit

Hosted by www.Geocities.ws

1