Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SECTION .data ; Section containing initialized data
- isEqual: dw "Perfect median occurs at maximum %d, median %d",10,0
- SECTION .global
- SECTION .bss ; Section containing uninitialized data
- lo resw 2
- hi resw 2
- deci resw 2
- SECTION .text ; Section containing code
- extern printf ; Print function from glibc
- global main ; Linker needs this to find the entry point
- main:
- nop ; This no-op keeps gdb happy
- push ebp ; Set up stack frame for debugger
- mov ebp,esp
- push ebx ; Must preserve EBP, EBX, ESI & EDI
- push esi
- push edi
- ; Everything before this is boilerplate; use it for all apps
- ;Set initial values
- mov ebx, 3 ;L1.
- mov esi, 2 ;L2
- L1:
- mov dword[lo], 1
- add dword[hi], ebx
- mov edi, dword[hi]
- mov dword[deci], edi
- L2:
- sub edi, dword[lo]
- jnz L3
- push esi
- push ebx
- push isEqual
- call printf
- add esp, 12
- L3:
- add dword[lo], esi ;Reset num2
- sub dword[deci], esi ;Reset edi
- sub dword[deci], 1
- mov edi, dword[deci]
- inc esi ;Increment esi (L2 looper)
- cmp esi, ebx ;
- jl L2 ;
- mov esi, 2 ;Reset esi
- inc ebx ;Increment ebx (L1 looper)
- cmp ebx, 10000 ;
- jl L1 ;
- ; Everything after this is boilerplate; use it for all apps
- pop edi ; Restore saved registers
- pop esi
- pop ebx
- mov esp,ebp ; Destroy stack frame before returning
- pop ebp
- ret ; Return control to Linux
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement