0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

#概要

wslでubuntuやってみた。
練習問題やってみた。

#練習問題

wslとpaizaで動く、fizzbuzzを書け。

#サンプルコード

.code64
.text
.global main

main:
    mov     $1, %cx
loop:
    mov     %cx, %ax
    mov     $15, %bl
    div     %bl
    cmp     $0, %ah
    jz      loop15
    mov     %cx, %ax
    mov     $5, %bl
    div     %bl
    cmp     $0, %ah
    jz      loop5
    mov     %cx, %ax
    mov     $3, %bl
    div     %bl
    cmp     $0, %ah
    jz      loop3
	mov 	%cx, %ax
loop2:
    push    %cx
	call 	bin2dec
    pop     %cx
loop1:
	add     $1, %cx
	cmp     $101, %cx
    jnz     loop
	ret

loop15:
    mov 	$fizzbuzz, %rsi
    mov     $1, %rdi
    mov     $9, %rdx
    mov     $1, %rax
    push    %cx
    syscall
    pop     %cx
    jmp     loop1
    
loop5:
    mov 	$buzz, %rsi
    mov     $1, %rdi
    mov     $5, %rdx
    mov     $1, %rax
    push    %cx
    syscall
    pop     %cx
    jmp     loop1
    
loop3:
    mov 	$fizz, %rsi
    mov     $1, %rdi
    mov     $5, %rdx
    mov     $1, %rax
    push    %cx
    syscall
    pop     %cx
    jmp     loop1
	
bin2dec:
    mov     $100, %bl
    div     %bl
    push    %ax
    call    putd
    pop     %ax
    mov     %ah, %al
    and     $0xff, %ax
    mov     $10, %bl
    div     %bl
    push    %ax
    call    putd
    pop     %ax
    mov     %ah, %al
    call    putd
    mov     $10, %ax
    call    putd
    ret
    
putd:
    and     $0x0f, %rax
    mov     $num, %rsi
    add     %rax, %rsi
    mov     $1, %rdi
    mov     $1, %rdx
    mov     $1, %rax
    push    %cx
    syscall
    pop     %cx
    ret
	
.data
fizz:
	.ascii 	"Fizz "
buzz:
	.ascii 	"Buzz "
fizzbuzz:
	.ascii 	"FizzBuzz "	
num:
	.ascii 	"0123456789 "
	


#成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?