June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
40
Task/Loops-While/X86-Assembly/loops-while.x86
Normal file
40
Task/Loops-While/X86-Assembly/loops-while.x86
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
; NASM 64 bit X86-64 assembly on Linux
|
||||
|
||||
global main
|
||||
extern printf
|
||||
|
||||
segment .data
|
||||
|
||||
printffmt db `%ld\n`,0
|
||||
|
||||
segment .text
|
||||
|
||||
main:
|
||||
push rbp
|
||||
mov rbp,rsp
|
||||
|
||||
; used rbx and r12 because printf preserves these values
|
||||
|
||||
mov rbx,1024 ; start with 1024
|
||||
mov r12,2 ; load 2 as divisor
|
||||
|
||||
.toploop ; top of while loop
|
||||
cmp rbx,0 ; compare to 0
|
||||
jle .done ; exit 0 or less
|
||||
|
||||
lea rdi,[printffmt] ; print number in rsi
|
||||
mov rsi,rbx ; mov to rsi as argument
|
||||
call printf
|
||||
|
||||
; calculate n/2 and save
|
||||
xor rdx,rdx ; clear rdx for division
|
||||
mov rax,rbx ; mov number to rax for division
|
||||
idiv r12 ; divide by 2
|
||||
mov rbx,rax ; save n/2
|
||||
|
||||
jmp .toploop ; next loop
|
||||
|
||||
.done
|
||||
xor rax,rax ; return code 0
|
||||
leave ; fix stack
|
||||
ret ; return
|
||||
Loading…
Add table
Add a link
Reference in a new issue