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?

中古ノート、買ってみた。 その116

0
Posted at

概要

中古ノート買ってみた。
wsl1のubuntu18.04にnasm入れてみた。
練習問題、やってみた。

練習問題

マクロを組め。

実行結果


# gcc -o intarith_64 intarith_64.s -no-pie

# ./intarith_64
c=5, a=9, b=3, c=5
c=a+b, a=9, b=3, c=12
c=a-b, a=9, b=3, c=6
c=a*b, a=9, b=3, c=27
c=c/a, a=9, b=3, c=3

サンプルコード

.intel_syntax noprefix
.global main
.extern printf
.text

.macro pabc i, src
.data
	str\i: .string "\src"
.text
	mov		rdi, OFFSET FLAT:fmt4
	mov		rsi, OFFSET FLAT:str\i
	mov		edx, dword ptr [a]
	mov		ecx, dword ptr [b]
	mov		r8d, dword ptr [c]
	mov		eax, 0
	call	printf
.endm

main:
	push 	rbp
lit5:
	mov		eax, 5
	mov		[c], eax
	pabc	1, "c=5"
addb:
	mov		eax, dword ptr [a]
	add		eax, dword ptr [b]
	mov		[c], eax
	pabc	2, "c=a+b"
subb:
	mov		eax, dword ptr [a]
	sub		eax, dword ptr [b]
	mov		dword ptr [c], eax
	pabc	3, "c=a-b"
mulb:
	mov		eax, dword ptr [a]
	imul		dword ptr [b]
	mov		[c], eax
	pabc	4, "c=a*b"
diva:
	mov		eax, dword ptr [c]
	mov		edx, 0
	idiv		dword ptr [a]
	mov		[c], eax
	pabc	5, "c=c/a"
_end:
	pop		rbp
	mov		eax, 0
	ret

.data
	a:			.int	9
	b:			.int	3
	fmt4:		.string "%s, a=%ld, b=%ld, c=%ld  \n"

.bss
	.comm 		c, 1





以上。

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?