0

I have an Unsigned Number

  • in registers %rdi/edi/di I have 0xFFFE
  • in registers %rsi/esi/si I have 0x4.

The objective is to do addw %di, %si

Firstly, I want to know... what values are put into %si and why? I'm still not 100% clear on that.

Secondly, I need to know: What types of flags does this one contain? I have read what makes a flag appear, but its not entirely clear at all which flags appear or why even when the book tells me point blank.

The_Senate
  • 139
  • 5
  • 1
    assembly must be tagged with the architecture. And a register doesn't carry any flags – phuclv Oct 19 '18 at 01:31
  • I think this is ATT in C. Also, it doesn't? So, what does carry the flags? – The_Senate Oct 19 '18 at 01:32
  • You can think of flags as 1 bit registers. – Havenard Oct 19 '18 at 01:36
  • 1
    See [Art of Assembly eflags register](http://www.plantation-productions.com/Webster/www.artofasm.com/Linux/HTML/HelloWorlda3.html#998367) and more generally all editions [Art of Assembly](http://www.plantation-productions.com/Webster/www.artofasm.com/) – David C. Rankin Oct 19 '18 at 01:41
  • AT&T is a syntax, not architecture – phuclv Oct 19 '18 at 01:54
  • @The_Senate The flags are stored in the separate `flags` register. This register is not directly accessibly as an operand but it can be pushed and popped with `pushf` and `popf` or moved to/from `ah` with `sahf` and `lahf`. – fuz Oct 19 '18 at 08:39

1 Answers1

2

For unsigned numbers you can zero extend it by adding any number of 0s in front of it. So RSI here is 0x0000000000000004. SI is the lower 16 bit of RSI so it is 0x0004.

RDI is 000000000000FFFE 
EDI is         0000FFFE 
DI  is             FFFE

RSI is 0000000000000004
ESI is         00000004
SI  is             0004

All the registers store the number and don't contain any flag. In fact, the CPU cannot even tell whether a number is signed or unsigned.

The CPU has only one flags register, and it normally can only be set according to the result of an arithmetic or comparison operation. For example, moving 0xFFFE to DI has no effect on the flags. You have to use testw %di, %di to compare DI to itself and then the flags will be changed accordingly.

MOV  DI, 0xFFFE ; flags are not changed
TEST DI, DI     ; flags are changed according to the result of TEST
JZ   .A         ; will not jump because ZF (Zero Flag) is not set because DI is not zero
JS   .B         ; will jump because SF (Sign Flag) is set because the highest bit of DI is 1
Sep Roland
  • 20,265
  • 3
  • 36
  • 58
W. Chang
  • 484
  • 3
  • 8
  • you should avoid using 16-bit registers, because they need the 66h prefix, resulting in **longer instructions**, and they are also **slower** due to the partial register stall and the microcode decoding step. 32-bit registers are often better [On 32-bit CPUs, is an 'integer' type more efficient than a 'short' type?](https://stackoverflow.com/q/163254/995714), [Why run 16-bit programs on x86 operating systems get slower?](https://stackoverflow.com/q/20145903/995714) – phuclv Oct 21 '18 at 04:09
  • [Why are mov ah,bh and mov al, bl together much faster than single instruction mov ax, bx?](https://stackoverflow.com/q/7031671/995714), [Understanding partial-register slowdowns from mov instead of movzx instruction](https://stackoverflow.com/q/47052342/995714), [Why doesn't GCC use partial registers?](https://stackoverflow.com/q/41573502/995714), [What is a Partial Flag Stall?](https://stackoverflow.com/q/49867597/995714) – phuclv Oct 21 '18 at 04:10