I
I
impressive172021-02-08 15:54:27
assembler
impressive17, 2021-02-08 15:54:27

How is work with short in asm?

I have work with variable char
Here is a piece of code
short right = acum & 65535;
short left = acum" 16;
and I see this in the asm code
00000230: andi r16,r16,65535
//here the sign bit is inverted as I understand it
00000234: xori r16,r16,32768
00000238: addi r16,r16,-32768
Please tell me the meaning of such conversions? Why is the last addition operation necessary?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2021-02-08
@jcmvbkbc

00000234: xori r16,r16,32768
00000238: addi r16,r16,-32768

This is a classic extension of the sign bit, in this case for a 16-bit number: if bit 15 was set (the number is negative), then after xor it will be reset (i.e. it and all bits older than it will become zero), and after addi bit 15 and all older than him will become units. If bit 15 was cleared (non-negative number), then after xor it will be set, and after addi it will be cleared again.
Could you please tell me the meaning of such transformations?

The sign extension is part of the short right = acum & 65535;. It is necessary in order to work with values ​​loaded into registers without thinking about the initial width of their data type. Those. (short)-1in a 64-bit register will be represented as 0xffffffffffffffff, not 0xffff.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question