我正在制作一個程式,而不是“1bc”寫“ONEbc”。但是,我正在努力將一個字串插入另一個字串。我設法做到了程式會更改每個字符,但我需要插入一個完整的字串,而不是逐個符號地插入,同時我的程式也不會列印文本的其余部分(只是“一個”)。這是將 1 變為 ONE 的段。
.DATA
one db "ONE" ; I want to include this into my code somehow
**************************************************
MOV cx, ax
MOV si, offset firstBuf ; (firstBuf db "1bc")
MOV di, offset newBuf ; (should be "ONEbc" after this)
work:
MOV dl, [si]
CMP dl, '1'
JNE continue
ADD ax, 3
MOV cx, ax
MOV [di], 'O'
INC si
INC di
MOV [di], 'N'
INC si
INC di
MOV [di], 'E'
JMP next
continue:
MOV [di], dl
next:
INC si
INC di
LOOP work
如您所見,我嘗試過逐個符號地放置字串,但我認為有更好的方法來做到這一點。我是初學者,我正在使用 emu8086,如果有幫助的話。
uj5u.com熱心網友回復:
由于 SI 暫存器上的 2 個額外增量,輸出未顯示“bc”!在回圈中間更改 CX 將導致讀取超過源字串,所以也不要這樣做。
MOV cx, ax ; Length of the input string
work:
MOV dl, [si]
INC si
CMP dl, '1'
JNE continue
ADD ax, 2 ; New length of the output string we're building
MOV [di], 'O'
INC di
MOV [di], 'N'
INC di
MOV dl, 'E'
continue:
MOV [di], dl
INC di
LOOP work
我試過一個符號一個符號地放置字串,但我認為有更好的方法來做到這一點。
您可以一起輸出 2 個字符:
MOV cx, ax ; Length of the input string
work:
MOV dl, [si]
INC si
CMP dl, '1'
JNE continue
ADD ax, 2 ; New length of the output string we're building
MOV word [di], 'ON'
ADD di, 2
MOV dl, 'E'
continue:
MOV [di], dl
INC di
LOOP work
您還可以從其他地方檢索“ONE”字串。如果要插入的文本稍長一些,則尤其有趣。
MOV cx, ax ; Length of the input string
work:
MOV dl, [si]
INC si
CMP dl, '1'
JNE continue
mov bx, OFFSET one
mov bp, 2
add ax, bp ; New length of the output string we're building
nestedLoop:
mov dl, [bx]
inc bx
mov [di], dl
inc di
dec bp
jnz nestedLoop
mov dl, [bx]
continue:
MOV [di], dl
INC di
LOOP work
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/533859.html
