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?

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

0
Last updated at Posted at 2025-12-02

概要

中古ノート買ってみた。
wsl1のubuntu18.04にnasm入れてみた。
nasmをgasに置き換えてみた。

環境

windows10
wsl1
ububtu18.04

手順

  • nasm->gas
  • .intel_syntax noprefix使う。
  • .comm使う。
  • .string使う。
  • [rip]使う。

サンプルコード

大きさ 7 の欠片を大きさ 3 以下の欠片に分ける最小の切断回数を 1 行で出力してください。
答えは2。

.intel_syntax noprefix
.global main
.extern scanf, printf
.text

main:
	sub 	rsp, 8
	lea 	rdi, fmti[rip]
	lea 	rsi, a[rip]
	call 	scanf

	lea 	rdi, fmti[rip]
	lea 	rsi, b[rip]
	call 	scanf

	mov 	eax, a[rip]
	sub 	eax, 1
	mov		edx, 0
	mov 	ecx, b[rip]
	div 	ecx
	lea 	rdi, fmto[rip]
	mov 	rsi, rax
	call 	printf

done:
	add 	rsp, 8
	mov 	rax, 0
	ret

.data
	fmti: 	.string "%d"
	fmto:	.string "%d \n\0"

.bss
	.comm 	a, 4
	.comm 	b, 4


コンパイル、実行結果

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

# ./oupc
7
3
2

以上。

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?