ia-32

Working with double-precision numbers in inline assembly (GCC, IA-32)

浪尽此生 提交于 2019-11-30 14:42:10
I'm just starting to learn assembly in my computer science class, and I have an assignment to round a floating-point value using a specified rounding mode. I've tried to implement this using fstcw , fldcw , and frndint . I modify the rounding control bits, round the number, and then restore the previous control bits (a requirement of the assignment). The current outstanding problem is that the instruction fld %1 seems to load the wrong value into the st(0) floating-point register (for example, if I call the function with a value of 2.6207, the number -1.9427(...)e-29 gets loaded into the

XOR register,register (assembler)

那年仲夏 提交于 2019-11-29 13:43:45
From time to time we have to analyze pieces of assembler code (IA32), and more than often i come across an instruction that looks like this: xor ax, ax or with other registers aswell: xor dx, dx , xor al, al , ... What exactly does this do ? (ax xor ax always gives 0 ?) It's a common assembler idiom to set a register to 0. xor ax, ax corresponds to ax = ax ^ ax which, as you already notices, is effectively ax = 0 . If I recall correctly the main advantage is that its code-size is smaller than mov ax, 0 That is exactly what it does -- zero the contents of a register xor %ax, %ax, as stated in

Assembly: Read integer from stdin, increment it and print to stdout

不羁的心 提交于 2019-11-29 08:58:56
I coded the following assembly script for IA32. It is supposed to read a number from stdin, increment it and print it to stdout, but it does not behave as expected, it doesn't print anything (maybe the reading from stdin does not terminate or something with the printing is wrong?) .section .text .globl _start _start: movl $3, %eax # use syscall 3 (read) to read from stdin movl $0, %ebx # reads from stdin (FD 0) movl %edi, %ecx # store input in register %edi movl $4, %edx # read one byte int $0x80 # invoke system call to read from stdin incl %edi # increment the value we got from stdin movl $4,

Binary Bomb Phase 5

不想你离开。 提交于 2019-11-29 08:57:55
I have been working on a Binary Bomb for school, and I am absolutely lost in Phase 5. The object of the assignment is to dissemble the code and find a string, which I have found to be "flyers" and reverse engineer it to have the same numerical value as "flyers" does. However, I have spent the last 3-4 hours trying to find out how to do this? You don't have to give answers, but PLEASE help me understand what I need to do. Here is the disassembled code using gdb: Dump of assembler code for function phase_5: 0x08048d88 <+0>: push %ebx 0x08048d89 <+1>: sub $0x28,%esp 0x08048d8c <+4>: mov 0x30(%esp

Why does IA-32 have a non-intuitive caller and callee register saving convention?

不羁岁月 提交于 2019-11-28 00:28:41
The common calling conventions for IA-32 say: • Callee-save registers %ebx, %esi, %edi, %ebp, %esp Callee must not change these. (Or restore the caller's values before returning.) • Caller-save registers %eax, %edx, %ecx, condition flags Caller saves these if it wants to preserve them. Callee can freely clobber. Why does this strange convention exist? Why not save all the registers before calling another function? Or have the callee save and restore everything with pusha / popa ? Why would you want to write code to save registers in every function that you might not need? That would add extra

Why is it not possible to push a byte onto a stack on Pentium IA-32?

橙三吉。 提交于 2019-11-27 14:43:40
I've come to learn that you cannot push a byte directly onto the Intel Pentium's stack, can anyone explain this to me please? The reason that I've been given is because the esp register is word-addressable (or, that is the assumption in our model) and it must be an "even address". I would have assumed decrementing the value of some 32-bit binary number wouldn't mess with the alignment of the register, but apparently I don't understand enough. I have tried some NASM tests and come up that if I declare a variable (bite db 123) and push it on to the stack, esp is decremented by 4 (indicating that