如何在nasm 64位中显示数据和地址?

时间:2018-01-26 13:53:52

标签: nasm

我正在做一个实际的任务。我制作了一个数组,我希望以格式(address: data)同时显示数据和地址。怎么做?我的代码需要做哪些更改?如何再次使用rsi来显示地址? 我的代码的链接是: http://rextester.com/AQMJ86771

1 个答案:

答案 0 :(得分:0)

通常情况下为某人做作业不是好习惯,但因为你太近了,我会忍不住

    %macro disp 2
        push    rsi
        push    rcx
        mov rax,1
        mov rdi,1
        mov rsi,%1
        mov rdx,%2
        syscall

        pop    rcx
        pop    rsi
    %endmacro

    section .data
        msg1 db "Menu : ",10
             db "1.NOWOS",10
             db "2.NOWS ",10
             db "3.OWOS ",10
             db "4.OWS  ",10
        l1 equ $-msg1
        newline db 0AH
        colon db ' : '
        src dq 01H,02H,03H,04h,05h
        dst dq 00h,00h,00h,00h,00h

    section .bss
        buff resb 16
        pcount resb 1
        ncount resb 1

    section .code
    global _start
    _start:
        disp msg1,l1
        mov rsi,src
        mov rcx,5
    back:
        mov     rax, rsi
        call    disp16num
        disp    colon, 3
        lodsq
        call    disp16num
        disp    newline,1
        loop    back

        mov rax,60
        mov rdi,0
        syscall

    disp16num:
       push    rcx
       push    rsi
       mov     rsi, buff
       mov     rcx, 16
       mov     rbx, rax
    back1:
       rol rbx,4
       mov al,bl
       and al,0FH
       cmp al,09H
       jbe add30
       add al,7H
    add30:
        add al,30H
        mov [rsi],al
        inc rsi
        loop back1
        disp buff,16
        pop     rsi
        pop     rcx
        ret

这将为您提供此输出。

菜单:
1.NOWOS
2.NOWS
3.OWOS
4.OWS
00000000006001B4:0000000000000001
00000000006001BC:0000000000000002
00000000006001C4:0000000000000003
00000000006001CC:0000000000000004
00000000006001D4:0000000000000005