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?
- What’s the purpose of the LEA instruction?
- Understanding cmp instruction
- 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
- Assembly: How does fld st(0) duplicates the top stack value in the following code?
- What does the MOVZBL instruction do in IA-32 AT&T syntax?
- What’s the purpose of the LEA instruction?
- ARM Assembler – How do I use CMP, BLT and BGT?
- The difference between cmpl and cmp
- x86 cmpl and jne
- 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
- Purpose of ESI & EDI registers?
- What are the ESP and the EBP registers?
- IDIV operation in assembly (understanding)
- waitpid, wnohang, wuntraced. How do I use these
- Convert C program into assembly code
- How to initialize array to 0 in C?
- How to do scanf for single char in C
- Sign extend a nine-bit number in C
- Warning: assignment from incompatible pointer type
- Break statement not within loop or switch in C
- How to properly malloc for array of struct in C
- Cache Simulator in C
- C: error: expected ‘)’ before ‘;’ token
- Where is the C auto keyword used?
- make: Nothing to be done for `all’
- Data argument not used by format strings in C
- execv vs execvp, why just one of them require the exact file’s path?
- difference between
and - expected expression before ‘{‘ token
- Setting std=c99 flag in GCC
- C Vector/ArrayList/LinkedList
- 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?
- Returning an array using C
- warning: initializer element is not computable at load time
- What is stdin in C language?
- How to prevent multiple definitions in C?
- How to pass 2D array (matrix) in a function in C?
- explanation about push ebp and pop ebp instruction in assembly
- error: ‘for’ loop initial declarations are only allowed in C99 mode [duplicate]
- How can you print multiple variables inside a string using printf?
- c – warning: implicit declaration of function ‘printf’
- Flushing buffers in C
- What are 0x01 and 0x80 representative of in C bitwise operations?
- How to make parent wait for all child processes to finish?
- Undefined Reference issues using Semaphores
- What is time(NULL) in C?
- Use of cudamalloc(). Why the double pointer?
- 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
- Portable way to check if directory exists [Windows/Linux, C]
- OpenGL — GL_LINE_LOOP —
- too many arguments for format [-Wformat-extra-args]
- How to use EOF to run through a text file in C?
- Incorrect checksum for freed object on malloc
- Valgrind complains with “Invalid write of size 8”
- what does the cmpq instruction do?
- Expression must be a pointer to a complete object type using simple pointer arithmetic
- How to copy a char array in C?
- Simple way to check if a string contains another string in C?
- What does “request for member ‘*******’ in something not a structure or union” mean?
- cast to pointer from integer of different size, pthread code
- Invalid type argument of unary ‘*’ (have ‘int’) Error in C
- Segmentation fault (core dumped) due to fgets – I think
- 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
- What does “request for member ‘*******’ in something not a structure or union” mean?
- Unknown ending signal when using debugger gdb
- Valgrind: invalid read of size 4 -> sigsegv, works fine without valgrind and in visual studio
- error: too few arguments to function `printDay’ (C language)
- How to convert integer to char in C?
- Is there a good Valgrind substitute for Windows?
- Purpose of ESI & EDI registers?
- Difference between sizeof(char) and sizeof(char *)
- Where to find the complete definition of off_t type?
- struct has no member named
- printf not printing to screen
- Bubble sort on array on Assembly Language