下のアセンブリプログラム(x86)をで入力した数字の約数を求めたいです。
下のコードですと、エラーが出てしまいます。
segment .data
Message db "Find primes up to: ", 0
segment .bss
Limit resd 1 ; find primes up to this limit
Guess resd 1 ; the current guess for prime
segment .text
global asm_main
asm_main:
enter 0,0 ; setup routine
pusha
mov eax, Message
call print_string
call read_int ; scanf("%u", & limit );
mov [Limit], eax
mov eax, 2 ; printf("2\n");
call print_int
call print_nl
mov eax, 3 ; printf("3\n");
call print_int
call print_nl
mov dword [Guess], 5 ; Guess = 5;
loop_start:
mov eax,[Limit]
mov ecx,eax
add eax,ecx
je eax,0
movabs ecx,eax
call print_int
call print_nl
loop loop_start
leave
ret
Cでいうと、
printf("Recieves a number(limit) and prints its all divisors");
for(int i = 1; i <= limit; i++) {
if((limit%i) == 0){
printf("\n%d", i);
だとは思うのです。
A 回答 (1件)
- 最新から表示
- 回答順に表示
No.1
- 回答日時:
自分でGCCなりのコンパイラ使ってアセンブリ吐かせてみました?
Ubuntuでgccでコンパイルすればこうなるかなぁ。
.file "chakisann_03.c"
.text
.section .rodata
.LC0:
.string "Find primes up to:"
.LC1:
.string "%9s%*[^\n]%*c"
.LC2:
.string "\n%d"
.text
.globl main
.type main, @function
main:
.LFB6:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
leaq .LC0(%rip), %rdi
movl $0, %eax
call printf@PLT
leaq -18(%rbp), %rax
movq %rax, %rsi
leaq .LC1(%rip), %rdi
movl $0, %eax
call __isoc99_scanf@PLT
leaq -18(%rbp), %rax
movl $10, %edx
movl $0, %esi
movq %rax, %rdi
call strtol@PLT
movl %eax, -24(%rbp)
movl $1, -28(%rbp)
jmp .L2
.L4:
movl -24(%rbp), %eax
movl $0, %edx
divl -28(%rbp)
movl %edx, %eax
testl %eax, %eax
jne .L3
movl -28(%rbp), %eax
movl %eax, %esi
leaq .LC2(%rip), %rdi
movl $0, %eax
call printf@PLT
.L3:
addl $1, -28(%rbp)
.L2:
movl -28(%rbp), %eax
cmpl -24(%rbp), %eax
jbe .L4
movl $10, %edi
call putchar@PLT
movl $0, %eax
movq -8(%rbp), %rcx
xorq %fs:40, %rcx
je .L6
call __stack_chk_fail@PLT
.L6:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE6:
.size main, .-main
.ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0"
.section .note.GNU-stack,"",@progbits
.section .note.gnu.property,"a"
.align 8
.long 1f - 0f
.long 4f - 1f
.long 5
0:
.string "GNU"
1:
.align 8
.long 0xc0000002
.long 3f - 2f
2:
.long 0x3
3:
.align 8
4:
いずれにせよ、「エラーが出ます」と言うより「どんなエラーなのか」明示した方が良いたぁ思いますけどね。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
pythonでAmazonのほしいものリ...
-
Web初心者です。 簡易的なWebペ...
-
Google ColaboでGUI作成
-
JRのjsonファイルって使って大...
-
HTMLソースが表示のページのも...
-
ホログラムを作ってくれる会社...
-
Google Colabでimport soxが出...
-
pythonでのカーソル移動がずれる
-
Lazarus(IDE2.2.6)をインスト...
-
Processingについて
-
16x16のスプライトフォント
-
初心者powershellのPS1ファイル...
-
vba クリップボードクリアにつ...
-
python の 連鎖代入の文法
-
大学のプログラミングの授業で...
-
Pythonを勉強しています。
-
python エラー
-
Pythonでの文字列からfloatへの...
-
・オブジェクト指向のメリット...
-
最新のプログラム言語を学ぶに...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
vba クリップボードクリアにつ...
-
Pythonでの文字列からfloatへの...
-
プログラミング言語について
-
matplotlibでのLaTex表示
-
Google ColaboでGUI作成
-
HLMT、CSSについて相談です。 ...
-
近年誕生したプログラミング言語
-
長門有希のようにコンピュータ...
-
hostファイル
-
プログラマーに向いている人の...
-
Win11で作業を自動化したいです...
-
Pythonを使ってせん断応力図、...
-
・オブジェクト指向のメリット...
-
ホログラムを作ってくれる会社...
-
このURLで広告を出しているのは...
-
エディターで以下のような色に...
-
google Colabでmatplotlibの描...
-
プログラマーは誘惑にさらされ...
-
VBAでパワーシェルを実行したい...
-
特定の項目セルにスキャン(入...
おすすめ情報