gpt4 book ai didi

linux - 程序集 - 数组 (Linux)

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:12:07 25 4
gpt4 key购买 nike

在汇编中如何打印数组的值?现在在这个程序中我还必须打印它的值<用户输入的索引。

.intel_syntax noprefix

.include "console.i"

.data

index: .long 0
array: .long 1,2,3,4,5,6,7,8,9,10,11,12 # Array initialized
value: .long 0


.text

ask1: .asciz "Enter an Index: "
ans: .asciz "Value= "
ask2: .asciz "Invalid Index"
ask3: .asciz "Goodbye!!"


_entry:

Prompt ask1
GetInt index

mov ebx, offset array # ebx = address of array

mov esi, index
cmp esi, 11 # comparing index with 11

ja 1f # if Index > 11,then jump
# to label 1

mov eax, [ebx + 4*esi]

mov value, eax

Prompt ans
PutInt value
PutEol


Prompt ask3
PutEol
ret

1: Prompt ask2
PutEol

Prompt ask3
PutEol
ret

.global _entry

.end

最佳答案

找到了解决方案

.intel_syntax noprefix

.include "console.i"

.data

limit: .long 0

array: .long 1,2,3,4,5,6,7,8,9,10,11,12 # Array initialized

value: .long 0

value2: .long 0

.text

ask1: .asciz "Enter an limit: "

ans: .asciz "Value= "

msg: .asciz "Invalid"

bie: .asciz "Goodbye!!"


_entry:

Prompt ask1

GetInt limit

mov ebx, offset array # ebx = address of array

mov ecx, 0

mov esi, limit # esi = index

cmp esi, 12 # comparing index with 12

jge 1f

Prompt ans

PutEol

2: mov eax, [ebx + 4 * ecx]

mov value, eax

inc ecx

PutInt value

Puteol

cmp ecx, esi

jle 2b

ret

1: Prompt msg

PutEol

Prompt bie

PutEol

ret

.global _entry

.end

关于linux - 程序集 - 数组 (Linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3582562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com