Hi, I'm learning SPARC assembly and I have to create a script that extracts a field from a register. The script accepts 3 values, initial number, field start position, field length.
It can't use any shift functions, but it can use multiply and divide.
I'm currently suffering from a respiratory virus, and am subsequently on a significant amount of drugs. I'm having a lot of difficulty figuring out where to even start on this.
Some direction would be greatly appreciated.
views:
408answers:
1
+3
A:
Multiply by 2 is a left-shift and divide by 2 is a right shift (at least for unsigned numbers).
If you want to left shift by 2 bits, that's a multiply by 4.
So, for example, if you have the binary value:
b15 b0
v V
0000 1111 0101 1000
and you wanted to extract b3 and b2, you would AND the whole lot with 0xc0 and divide by 4.
0000 1111 0101 1000
0000 0000 0000 1100 <- AND with 0xc0
-------------------
0000 0000 0000 1000
-------------------
0000 0000 0000 0010 <- divide by 4
Since this sounds suspiciously like homework (and I haven't coded for SPARC for a long time), I won't attempt to give you a finished solution - that should be enough to get you going.
paxdiablo
2009-02-12 06:01:53
Thanks! Yeah, I should have made it more clear; I was only looking for direction not a solution. This should be perfect, I'll see what I can do.
derrickp
2009-02-12 06:18:19