
-----------------------------------
greenapplesodaex
Thu Jan 05, 2006 7:02 pm

question about MIPS (assambly code)
-----------------------------------
i just started learning assambly code, and there's something i dont get

so there are 32 bit in a cpu $0 - $31, and bits are either 0 or 1, ja?

add $4, $5, $6 means $5+$6 and put that into $4

but then why are we just adding binary? and wouldnt $4 overfloat if $5 and $6 are both 1? 

thanx in advance

-----------------------------------
wtd
Thu Jan 05, 2006 7:44 pm


-----------------------------------
I'm fairly sure that what you're thinking of are 32 registers, each of which stores 32 bits.

-----------------------------------
Martin
Thu Jan 05, 2006 7:48 pm


-----------------------------------
That's right. 32, 32 bit registers with $0 being 0.

Moved to general programming.

-----------------------------------
greenapplesodaex
Thu Jan 05, 2006 8:27 pm

re
-----------------------------------
so you are saying that each of the $4 and $5 and the likes can all carry 32 bit in each?

-----------------------------------
wtd
Thu Jan 05, 2006 8:32 pm


-----------------------------------
Yes.

-----------------------------------
greenapplesodaex
Thu Jan 05, 2006 8:39 pm

re
-----------------------------------
so a mips has 32 registers $0 - $31, and each of the $something can store 32 bits, right? i think im getting this... thanx

-----------------------------------
Martin
Thu Jan 05, 2006 9:19 pm


-----------------------------------
Exactly.

Each block of memory can also store 32 bits, and a MIPS instruction is just a 32 bit integer. When a program is run, it is loaded into memory and then the memory is stepped through. This is why you have to use mflo and mfhi when you divide - you can't store a 32 bit value and an instruction within a 32 bit value (so the mflo and mfhi breaks it into two 16 bit values).

-----------------------------------
wtd
Thu Jan 05, 2006 9:21 pm


-----------------------------------
Yay for RISC.

-----------------------------------
greenapplesodaex
Thu Jan 05, 2006 9:32 pm

re
-----------------------------------
come again why you cant just operate on a 32 bit in the registry? and even if you break it in two 16 bits, but isnt is still 32 together? where's the instruction gonna stay then?

and is there a list for all the commenly used instructions?

thanx again in advance

-----------------------------------
Martin
Thu Jan 05, 2006 10:32 pm


-----------------------------------
You can't operate on 32 bits because you have to also store the instruction as well (so you need 32 bits for the number + n bits for the instruction). So you have to break it into two.

-----------------------------------
md
Thu Jan 05, 2006 10:45 pm


-----------------------------------
mflo and mfhi actually load the low 32bits and the high 32bits of the multiplication result into registers... I think what martin was refering to was llo and lhi.

Is this for CS241 at UW, and if so what class are you in?

-----------------------------------
greenapplesodaex
Fri Jan 06, 2006 9:32 am

re
-----------------------------------
ok, say i load the lo first, and it takes up 16 bits, which leaves 16 bits left in that register. i now load hi, which will also take up 16 bits, then wont it still not have enough spaces for the instruction and the hi all together?

-----------------------------------
md
Fri Jan 06, 2006 10:45 am


-----------------------------------
llo loads the low 16 bits of the number you give into a register, lhi does the same except with the high bits. In the assembly language file you can specify a number > 16bits however when it is assembled only the relevant 16 bits are kept. 


Say your loading teh number 16_DEADBEEF into a register. It's a 32bit number (it's hex), so you need to do it in two parts:

llo $5, 16_DEADBEEF
lhi $5, 16_DEADBEEF


When you call the assembler to turn your assembly into machine code it will only use the 16 bits it needs for each instruction, so basically it becomes

llo $5, 16_BEEF
lhi $5, 16_DEAD

** note that I'm not sure if this will work if you actually write it like this...

It's important to realize that assembly is not machine language. It's very close, but there are differences.

-----------------------------------
Martin
Sat Jan 07, 2006 3:45 am


-----------------------------------
It's pretty much as close as you can get to machine language without being machine language. You can write a conversion program in C++ that converts from MIPS to machine language in under 100 lines.  Every command in MIPS represents a 32 bit integer. Machine code is just a series of 32 bit integers.
