#概要
paizaでアセンブラ、やってみた。
練習問題やってみた。
#練習問題
printfは、使わないでfizzbuzz。
#サンプルコード
.code32
.text
.global main
main:
mov $1, %esi
loop:
mov %esi, %eax
mov $15, %ebx
div %bl
cmp $0, %ah
jz loop15
mov %esi, %eax
mov $5, %ebx
div %bl
cmp $0, %ah
jz loop5
mov %esi, %eax
mov $3, %ebx
div %bl
cmp $0, %ah
jz loop3
mov %esi, %eax
loop2:
push %esi
call bin2dec
pop %esi
loop1:
add $1, %esi
cmp $101, %esi
jnz loop
ret
loop15:
mov $fizzbuzz, %ecx
mov $4, %eax
mov $1, %ebx
mov $9, %edx
int $0x80
jmp loop1
loop5:
mov $buzz, %ecx
mov $4, %eax
mov $1, %ebx
mov $5, %edx
int $0x80
jmp loop1
loop3:
mov $fizz, %ecx
mov $4, %eax
mov $1, %ebx
mov $5, %edx
int $0x80
jmp loop1
bin2dec:
mov $100, %bl
div %bl
push %eax
call putd
pop %eax
mov %ah, %al
and $0xff, %eax
mov $10, %bl
div %bl
push %eax
call putd
pop %eax
mov %ah, %al
call putd
mov $10, %eax
call putd
ret
putd:
and $0x0f, %eax
mov $num, %ecx
add %eax, %ecx
mov $4, %eax
mov $1, %ebx
mov $1, %edx
int $0x80
ret
.data
fizz:
.ascii "Fizz "
buzz:
.ascii "Buzz "
fizzbuzz:
.ascii "FizzBuzz "
num:
.ascii "0123456789 "
#成果物
以上。