首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >程序集-数组(Linux)

程序集-数组(Linux)
EN

Stack Overflow用户
提问于 2010-08-27 16:44:31
回答 1查看 1.4K关注 0票数 1

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

代码语言:javascript
复制
.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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-27 19:27:43

得到了一个解决方案

代码语言:javascript
复制
.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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3582562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档