LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Assembling a 32 bit sample program in a 64 bit world (https://www.linuxquestions.org/questions/programming-9/assembling-a-32-bit-sample-program-in-a-64-bit-world-492409/)

debiant 10-14-2006 02:52 PM

Assembling a 32 bit sample program in a 64 bit world
 
Or argggg!

Ok So I'm trying to get a bit of sample code working so I did a little modification of a book example because in amd64 you can no longer use pushl, so I'm using pushq:

Code:

# cmovtest.s - An example of the CMOV instructions
.section .data
output:
  .asciz "The largest value is %d\n"
values:
  .int 105, 235, 61, 315, 134, 221, 53, 145, 117, 5
.section .text
.globl _start
_start:
  nop
  movl values, %ebx
  movl $1, %edi
  loop:
      movl values(, %edi, 4), %eax
      cmp %ebx, %eax
      cmova %eax, %ebx
      inc %edi
      cmp $10, %edi
  jne loop
  pushq %rbx
  pushq $output
  call printf
  addl $8, %esp
  pushq $0
  call exit

I have debugged and the seg fault occurs during the call to printf. Everything seems to function fine through the loop (all of the register values are what they should be). I guess I don't understand the magic going on with pushq enough to fix this myself. Any help would be greatly appreciated.

PS: This is being assembled on an amd64 Ubuntu with gas linking against ld-linux-x86-64.so.2


All times are GMT -5. The time now is 08:44 AM.