如何在nasm中打印反向字符串?

时间:2018-05-15 14:07:28

标签: assembly nasm x86-16

如何在nasm中打印反向字符串?

我有这段代码:

BITS 16
org 0x7C00
_start:
    xor ax,ax           ; set ax register to 0
    mov ds,ax           ; set data segment(ds) to 0
    mov es,ax           ; set extra segment(es) to 0
    mov bx,0x8000
    mov si,string
    call reverse_print
    jmp $
reverse_print:
    mov ah,0Eh
.rep_pre:
    inc si
    cmp al,0
    je .rep_init
    jmp .rep_pre
.rep_init:
    dec si
    jmp .rep
.rep:
    std
    lodsb
    cmp al,0
    je .done
    int 10h
    jmp .rep
.done:
    cld
    ret
    string db "ABC",0
    times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
    dw 0xAA55       ; The standard PC boot signature

字符串是:

ABC

STDOUT是:

A├ⁿ ⌡Θ⯈=♣t

例外STDOUT:

CBA

是否可以纠正STDOUT没有超出STDOUT的错误?

编辑1

我扩展了代码并修复了错误和错误。

现在代码看起来:

BITS 16
org 0x7C00
_start:
    xor ax,ax           ; set ax register to 0
    mov ds,ax           ; set data segment(ds) to 0
    mov es,ax           ; set extra segment(es) to 0
    mov bx,0x8000
    mov si,string
    call reverse_print
    jmp $
reverse_print:
    mov ah,0Eh
    mov cx,1
.rep_pre:
    inc si
    inc cx
    cmp al,0
    je .rep_init
    jmp .rep_pre
.rep_init:
    inc si
    inc cx
    jmp .rep
.rep:
    std
    lodsb
    dec cx
    cmp al,0
    je .done
    cmp cx,0
    jl .done
    int 10h
    jmp .rep
.done:
    cld
    ret
    string db "ABC",0
    times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
    dw 0xAA55       ; The standard PC boot signature

我使用CX寄存器设置为1更正了一些错误。

现在STDOUT将此视为例外

CBA

0 个答案:

没有答案