The first part of Mysticials answer is correct, idiv
does a 128/64 bit division, so the value of rdx
, which holds the upper 64 bit from the dividend must not contain a random value. But a zero extension is the wrong way to go.
As you have signed variables, you need to sign extend rax
to rdx:rax
. There is a specific instruction for this, cqto
(convert quad to oct) in AT&T and cqo
in Intel syntax. AFAIK newer versions of gas accept both names.
movq %rdx, %rbx cqto # sign extend rax to rdx:rax idivq %rbx
Related Posts:
- need help understanding the movzbl call in this function
- Display value found at given address gdb
- How to compile makefile using MinGW?
- xorl %eax – Instruction set architecture in IA-32
- Difference between “move” and “li” in MIPS assembly language
- Assembly x86 – “leave” Instruction
- How can one see content of stack with GDB?
- How do I compile the asm generated by GCC?
- MIPS to C Translation
- What does the LEAL assembly instruction do?
- C compiler for Windows?
- What does the MOVZBL instruction do in IA-32 AT&T syntax?
- What’s the purpose of the LEA instruction?
- How to move ST(0) to EAX?
- The point of test %eax %eax
- The difference between cmpl and cmp
- What is the function of the push / pop instructions used on registers in x86 assembly?
- What is callq instruction?
- Difference between JA and JG in assembly
- IDIV operation in assembly (understanding)
- How to do scanf for single char in C
- Break statement not within loop or switch in C
- How to properly malloc for array of struct in C
- Cache Simulator in C
- Where is the C auto keyword used?
- Convert char array to a int number in C
- Bind failed: Address already in use
- Warning/error “function declaration isn’t a prototype”
- What is the difference between %f and %lf in C?
- What is stdin in C language?
- How to prevent multiple definitions in C?
- How to pass 2D array (matrix) in a function in C?
- How can you print multiple variables inside a string using printf?
- C dynamically growing array
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- x86 Assembly pointers
- Mapping a numeric range onto another
- Why are hexadecimal numbers prefixed with 0x?
- x86 assembly: How does the ‘subl’ command work in AT&T syntax
- too many arguments for format [-Wformat-extra-args]
- what does the cmpq instruction do?
- How to copy a char array in C?
- cast to pointer from integer of different size, pthread code
- Invalid type argument of unary ‘*’ (have ‘int’) Error in C
- Why do I get “cast from pointer to integer of different size” error?
- C subscripted value is neither array nor pointer nor vector when assigning an array element value
- error: too few arguments to function `printDay’ (C language)
- Where to find the complete definition of off_t type?
- struct has no member named
- printf not printing to screen
- Which variable size to use (db, dw, dd) with x86 assembly?
- How do AX, AH, AL map onto EAX?
- What do numbers using 0x notation mean?
- Can I create an Array of Char pointers in C?
- Does stack grow upward or downward?
- Convert Little Endian to Big Endian
- JNZ & CMP Assembly Instructions
- Excess elements of scalar initializer for pointer to array of ints
- error C2371: ‘functionname’ redefinition: different basic types
- How does one represent the empty char?
- How to write to a file using open() and printf()?
- pop or add esp, 4 ? What is the difference?
- note: previous implicit declaration of ‘point_forward’ was here
- What is the difference between MOV and LEA?
- Can I define a function inside a C structure?
- What exactly is meant by “de-referencing a NULL pointer”?
- getc() vs fgetc() – What are the major differences?
- Can’t understand the working of getint() in C as per K&R
- Difference between JE/JNE and JZ/JNZ
- Tokenizing strings in C
- In C, what exactly happens when you pass a NULL pointer to strcmp()?
- “-bash: gcc: command not found” using cygwin when compiling c?
- How to format strings using printf() to get equal length in the output
- What do \t and \b do?
- Why and when to use static structures in C programming?
- Where does linux store my syslog?
- Example of waitpid() in use?
- Can a function return two values?
- Assembly Language – How to do Modulo?
- C: warning: excess elements in array initializer; near initialization for ‘xxx’ ; expects ‘char *’, but has type ‘int’
- write() to stdout and printf output not interleaved?
- How to know what the ‘errno’ means?
- Split string with multiple delimiters using strtok in C
- Printf was not declared in this scope
- warning: missing terminating ” character [enabled by default]
- How to free memory from char array in C
- Can I get Unix’s pthread.h to compile in Windows?
- Initializing 2D char array in C
- FFT in a single C-file
- Process exited with return value 3221225477
- How do I check if a string contains a certain character?
- malloc(sizeof(int)) vs malloc(sizeof(int *)) vs (int *)malloc(sizeof(int))
- %p Format specifier in c
- GDB no such file or directory
- Level vs Edge Trigger Network Event Mechanisms
- “Nothing to be done for makefile” message
- Convert Char to String in C
- [Binary Bomb – Phase 4
- What is the difference between signed and unsigned int
- `js` and `jb` instructions in assembly