Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 question about MIPS (assambly code)
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
greenapplesodaex




PostPosted: Thu Jan 05, 2006 7:02 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu Jan 05, 2006 7:44 pm   Post subject: (No subject)

I'm fairly sure that what you're thinking of are 32 registers, each of which stores 32 bits.
Martin




PostPosted: Thu Jan 05, 2006 7:48 pm   Post subject: (No subject)

That's right. 32, 32 bit registers with $0 being 0.

Moved to general programming.
greenapplesodaex




PostPosted: Thu Jan 05, 2006 8:27 pm   Post subject: re

so you are saying that each of the $4 and $5 and the likes can all carry 32 bit in each?
wtd




PostPosted: Thu Jan 05, 2006 8:32 pm   Post subject: (No subject)

Yes.
greenapplesodaex




PostPosted: Thu Jan 05, 2006 8:39 pm   Post subject: 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




PostPosted: Thu Jan 05, 2006 9:19 pm   Post subject: (No subject)

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




PostPosted: Thu Jan 05, 2006 9:21 pm   Post subject: (No subject)

Yay for RISC.
Sponsor
Sponsor
Sponsor
sponsor
greenapplesodaex




PostPosted: Thu Jan 05, 2006 9:32 pm   Post subject: 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




PostPosted: Thu Jan 05, 2006 10:32 pm   Post subject: (No subject)

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




PostPosted: Thu Jan 05, 2006 10:45 pm   Post subject: (No subject)

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




PostPosted: Fri Jan 06, 2006 9:32 am   Post subject: 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




PostPosted: Fri Jan 06, 2006 10:45 am   Post subject: (No subject)

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:
code:

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
code:

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




PostPosted: Sat Jan 07, 2006 3:45 am   Post subject: (No subject)

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.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: