Created
August 13, 2016 03:02
-
-
Save alanduan/1fdad2e7ca1fe56f42bcc9d2a02e776b to your computer and use it in GitHub Desktop.
[INSTRUCTION] DIV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; get value_addr % 0x10 | |
; | |
; yasm -f elf32 -o div.o -g stabs div.asm | |
; or | |
; yasm -f elf32 -o div.o -g dwarf2 div.asm | |
; | |
; ld -m elf_i386 -o div div.o | |
; | |
; run the program | |
; ./div | |
; | |
; then you can verify the value by comparing | |
; echo $? | |
; with | |
; nm div | grep value_addr | |
section .text | |
global _start | |
_start: | |
xor edx, edx | |
mov eax, value_addr | |
div dword [eax] | |
mov eax, 0x1 | |
mov ebx, edx | |
int 0x80 | |
section .data | |
value_addr dd 0x10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the divisor is 0 or the quotient does not fit in:
Program terminated with signal SIGFPE, Arithmetic exception.
section .text
global _start
_start:
xor edx, edx
mov edx, -1
mov eax, value_addr
div dword [eax]
mov eax, 0x1
mov ebx, edx
int 0x80
section .data
value_addr dd 0x10