1
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 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
練習問題やってみた。

練習問題

アセンブラでzundokoをやってみて。

サンプルコード

File.write "hello.s", """

.code64
.text
.global main
main:
	mov	 	$0, %rdx
	mov	 	$234, %al
loop:
    cmp     $4, %rdx
    je      printkiyosi
	mov	 	$5, %cl
	mul	 	%cl
	add	 	$1, %al
	cmp	 	$120, %al
	jb      printdoko
printzun:
    push    %rax
    push    %rdx
    mov   	$1, %rax;
	mov   	$1, %rdi;
	mov   	$zun, %rsi;
	mov   	$4, %rdx;
	syscall;
	pop     %rdx
	pop     %rax
	add     $1, %rdx
	jmp	 	loop
printdoko:
    push    %rax
    push    %rdx
    mov   	$1, %rax;
	mov   	$1, %rdi;
	mov   	$doko, %rsi;
	mov   	$5, %rdx;
	syscall;
	pop     %rdx
	pop     %rax
	mov     $0, %rdx
	jmp	 	loop
printkiyosi:
	mov   	$1, %rax;
	mov   	$1, %rdi;
	mov   	$kiyosi, %rsi;
	mov   	$13, %rdx;
	syscall;
	mov   	$0, %rax;
	syscall;
.data
zun:
	.asciz "zun "
doko:
	.asciz "doko "
kiyosi:
	.asciz "doko kiyosi!!"  

"""

{result, 0} = System.shell("gcc -no-pie hello.s")
IO.puts result

{result, 0} = System.shell("./a.out")
IO.puts result



実行結果


zun zun doko zun zun zun doko doko zun doko zun zun doko doko doko doko zun zun doko doko zun doko doko zun zun doko doko doko doko doko zun zun zun zun doko kiyosi!!

成果物

以上。

1
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
1
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?