在Assembly中用下划线替换空格

时间:2015-11-18 18:44:16

标签: assembly x86 x86-16 16-bit as88

    _EXIT = 1
    _READ = 3
    _WRITE = 4
    _STDIN = 0
    _STDOUT = 1

    BUFFSIZE = 80
.SECT .TEXT
start:
    PUSH    endpr-prompt    ! print prompt
    PUSH    prompt
    PUSH    _STDOUT     ! on standard output
    PUSH    _WRITE
    SYS
    ADD SP,8        ! clean up stack
    PUSH    BUFFSIZE    ! read input line
    PUSH    buff
    PUSH    _STDIN      ! from standard input
    PUSH    _READ
    SYS
    ADD SP,8        ! clean up stack

    !! assert: AX holds number of bytes that were read
    MOV DX,AX
    ADD DX,buff     ! set DX to addr of first byte after input
    MOV BX,buff     ! initialize loop
1:  !! loop invar: all non-space chars before (BX) have been printed
    CMP BX,DX       ! if unprocessed bytes remain in buff...
    JE  9f
    CMPB    (BX),' '    ! then if next byte is not a space...
    JE  2f
    PUSH    1       ! print that byte
    PUSH    BX
    PUSH    _STDOUT
    PUSH    _WRITE
    SYS
    ADD SP,8
2:  INC BX      ! move to next char of buff
    JMP 1b      ! end of loop


9:  PUSH    0       ! normal exit status
    PUSH    _EXIT       ! end program
    SYS

.SECT .DATA
prompt: .ASCII "Enter input: "
endpr:
size:   .WORD   0       ! length of input

.SECT .BSS
buff:   .SPACE BUFFSIZE
endbuff:

目前,我的代码删除了字符串中的空格,但我无法弄清楚如何用新的预定义字符替换它。我对装配完全不熟悉。任何帮助,将不胜感激。如何指定一个字符来替换使用JE删除的''字符?

0 个答案:

没有答案