[nasm]四則演算

add,sub,mul,divを用いて演算を行う。
もちろん出力はASCIIコードで31hが1となるように計算。

結果は
5
1
6
3
と表示される

bits 64
section .text

global _main
_main:

	;足し算 5を出力
	mov rbx, 33h
	mov rcx, 02h
	add rbx, rcx
	push rbx
	mov rdx, 02h
	lea rsi, [rsp] ;link stack point adress to rsi
	mov rax, 0x2000004
	mov rdi, 1
	syscall

	xor rbx,rbx
	mov rbx, 10d
	push rbx
	mov rdx, 02h
	lea rsi, [rsp] ;link stack point adress to rsi
	mov rax, 0x2000004
	mov rdi, 1
	syscall

	;引き算 1を出力
	mov rbx, 33h
	mov rcx, 02h
	sub rbx, rcx
	push rbx
	mov rdx, 02h
	lea rsi, [rsp] ;link stack point adress to rsi
	mov rax, 0x2000004
	mov rdi, 1
	syscall

	xor rbx,rbx
	mov rbx, 10d
	push rbx
	mov rdx, 02h
	lea rsi, [rsp] ;link stack point adress to rsi
	mov rax, 0x2000004
	mov rdi, 1
	syscall

	;掛け算mulは引数をraxと掛けてraxに格納
	mov rax, 3
	mov rbx, 2
	mul rbx  
	add rax,30h
	push rax
	mov rdx, 02h
	lea rsi, [rsp] ;link stack point adress to rsi
	mov rax, 0x2000004
	mov rdi, 1
	syscall

	xor rbx,rbx
	mov rbx, 10d
	push rbx
	mov rdx, 02h
	lea rsi, [rsp] ;link stack point adress to rsi
	mov rax, 0x2000004
	mov rdi, 1
	syscall

	;割り算 divは引数でraxを割ってraxに格納
	mov rax, 6
	mov rbx, 2
	div rbx  
	add rax,30h
	push rax
	mov rdx, 02h
	lea rsi, [rsp] ;link stack point adress to rsi
	mov rax, 0x2000004
	mov rdi, 1
	syscall

	xor rbx,rbx
	mov rbx, 10d
	push rbx
	mov rdx, 02h
	lea rsi, [rsp] ;link stack point adress to rsi
	mov rax, 0x2000004
	mov rdi, 1
	syscall


	mov rax, 0x2000001
	mov rdi, 0
	sys call