Assembly addq clarification

The addq a,b instruction adds the contents of a to b. So if rcx = 0x1, rax = 0x100 and we have 0xff at address 0x100, then add %rcx,(%rax) adds 0x1 in rcx to 0xff at address 0x100, yielding 0x100 at address 0x100 as the worksheet correctly indicates. Your intuition would be correct if the instruction was movq instead of addq as movq just overwrites a memory location or register instead of adding to it.

When and why do we sign extend and use cdq with mul/div?

Use cdq / idiv for signed 32-bit / 32-bit => 32 bit division,xor edx,edx / div for unsigned. With the dividend in EAX to start with, and the divisor specified as an operand to DIV or IDIV. If you zero EDX/RDX instead of sign-extending into EDX:EAX before idiv, you can get a large positive result for -5 / 2, for example. Using the “full … Read more

MIPS Assembly – lui $t0, 4097?

4097 = 1001 hex so, the first instruction puts 0x10010000 into register t0. lui is “load upper immediate”, with “upper” meaning the upper 16 bits, and “immediate” meaning that you are giving it a literal value (4097). 4097 as an “upper” value becomes 0x10010000. ori is “or immediate”, with 8 being the immediate value, so … Read more

Purpose of ESI & EDI registers?

There are a few operations you can only do with DI/SI (or their extended counterparts, if you didn’t learn ASM in 1985). Among these are Which are, respectively, operations for repeated (= mass) storing, loading and scanning. What you do is you set up SI and/or DI to point at one or both operands, perhaps put a … Read more