Welcome! Log In Create A New Profile

# signed binary representation

Posted by arasium
 arasium signed binary representation July 20, 2010 10:09AM Registered: 10 years agoPosts: 161
Hi everybody.

I've this piece of code in the DI Module:

```var_30= -0x30
var_2C= -0x2C
var_28= -0x28

PUSH    {R4-R6,LR}
SUB     SP, SP, #0x20
MOVS    R4, R1
MOVS    R1, #0x58 ; 'X'
MOV     R6, SP
NEGS    R1, R1
LSLS    R3, R3, #0x18
MOVS    R5, R0
STRB    R1, [R6,#0x30+var_30]
STR     R4, [SP,#0x30+var_2C]
STR     R2, [SP,#0x30+var_28]
CMP     R3, #0```

Then the SP register is passed to the HandleDiCommand function.
So my question is about R1 and the di command associated.
Why doing "NEGS R1, R1" and then "STRB R1, [R6,#0x30+var_30]"? If i'm correct, the NEGS will only modify the MSBit.

So, i will have: R1 = 0b10000000 00000000 00000000 01011000

But then, if we only store one byte in the [R6,#0x30+var_30], why doing the NEGS before?

Perhaps the signed values aren't just with a sign bit (One's Complement or two's), and in this case, the NEGS have a real goal :)

Edited 2 time(s). Last edit at 07/20/2010 10:33AM by arasium.
 arasium Re: signed binary representation July 20, 2010 10:37AM Registered: 10 years agoPosts: 161
I will answer to my question :)

If the signed number user the two's complement representation, we will have (only for the LSB of R1) something like that:

R1 = 0x58
so
R1 = 0b01011000
so
NEGS R1 = 0b10101000
so
NEGS R1 = 0xA8

And A8 is the Read Command (wich is correct, because we are in a reading function).
 Daid Re: signed binary representation July 20, 2010 05:38PM Registered: 10 years agoPosts: 379
Almost everything uses 2 complement numbers these days. [en.wikipedia.org]

So, I think the NEG instruction does:
Invert all bits.