【问题标题】:Assembly - Array (Linux)组装 - 阵列 (Linux)
【发布时间】:2010-08-27 08:44:30
【问题描述】:

在汇编中我如何打印数组的值? 现在在这个程序中,我还必须打印它的值

.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

【问题讨论】:

  • mov ecx, [ebx] 会有所帮助吗?以便我稍后将其移入一个值并打印。
  • 我试过 mov ecx, [ebx] 但它只打印数组的第一个值。 :(

标签: linux arrays assembly ubuntu x86


【解决方案1】:

有意见

.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

【讨论】:

    猜你喜欢
    • 2015-01-20
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    相关资源
    最近更新 更多