Skip to content

Instantly share code, notes, and snippets.

@alanduan
Created August 13, 2016 03:02
Show Gist options
  • Save alanduan/1fdad2e7ca1fe56f42bcc9d2a02e776b to your computer and use it in GitHub Desktop.
Save alanduan/1fdad2e7ca1fe56f42bcc9d2a02e776b to your computer and use it in GitHub Desktop.
[INSTRUCTION] DIV
; 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
@alanduan
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment