-5
  1. Given the following MIPS assembly program:
data

byte 2

word 9 10 17 18 20 22

word 4 8

-text

global

start

la Ss0, h

la Ssl, 6 (Ss0)

la $s2, s 1w $s3, -20 (Ss2)

sub $s4, $s2, $s3

li Svo, 10

syscall

(editor's note: this is not an accurate transcription of the image)

The starting address s is Ox1006000, what will be the of $s0, $s1, $s2, $s3 and $s4 after the execution?

Answer:

Ss0 = -30

$si = = 0x00000050

$s2 = 0x100600

Ss3 = 16 = 0x00000040

Ss4 = $s2 - S3 = Ox00004010
kikicode
  • 3
  • 1
  • Inaccurate text is maybe better than no text at all, but you should still fix your question to use code blocks instead of pictures of text. e.g. you have multiple instructions on one line, missing labels on your data, missing `.` in most directives, and `l` vs. `1` and `$` vs. `S`, maybe from OCRed text. – Peter Cordes Mar 22 '21 at 14:40
  • @kikicode - your edit makes the code *less* like the image from the older versions of the question. If you have a similar question about *similar* code, that's not a good reason to change the numbers and instructions in someone else's question. Normally I'd roll back an edit like that, but this whole question is such a mess... – Peter Cordes Mar 22 '21 at 19:05

1 Answers1

1

Assembly language, like other languages, has to have a way to put code & data together to make programs.  Data is stored in memory so each datum has an address.  Code (machine code instructions) are also stored in memory, so each instruction also has addresses.  Within the code or data, the assembler lays item out sequentially.

The .data directive informs the assembler that what comes next is data not code.  The names followed by : are labels.  Each given word in the data takes 4 bytes of storage (a .byte takes only 1 byte).

Did you notice that they give the address of s in the problem statement?  That's important.

The processor executes one instruction at a time.  So it starts at the start (.text means code is following) and executes that sequence of instructions, each in turn.  Labels are used for reference but take no space in the machine code or data (so they don't execute).  (Directives like .text inform the assembler but also don't execute on the processor.)

In order to understand 80% of the code, you have to know two only instructions: la and lw.  (You also need to understand data: where s is and that +/- 4 bytes a time from the address refers to next or previous memory word, respectively.)

The la is a pseudo instruction that expands, by the assembler, into two MIPS instructions.  It stands for "load address" and takes a register target and a label, and suffice it to say that it does what it seems: loads the address of the named label into the named target register.  It also advances the program counter so that the next instruction that the processor runs is the one in the next higher memory address.

The lw is a real machine instruction, and can be found by looking it up in the manual, or quick reference, such as here: https://inst.eecs.berkeley.edu/~cs61c/resources/MIPS_Green_Sheet.pdf

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53