TASM输出问题

时间:2015-10-12 08:26:13

标签: tasm

所以,我是TASM的全新人,所以我可能会犯错误。这是一个问题,但是,我希望得到一些帮助。

我需要组装一个程序,该程序接受来自用户的输入,并用它前面的字符替换所有间隙(因此,如果输入是b c,它应该打印aabbc)。我遇到的问题是我打印出的垃圾数据而不是我需要的数据。老实说,我不知道问题是什么,所以我要求帮助。

哦,就在提前,我在Windows 8上使用DosBox。

以下是代码:

.MODEL SMALL ;defines memory model
.STACK 100H ;reserves memory space
.DATA
insert equ 0ah
outsert equ 9h
ENDL equ '$'
GAP equ ' '
;db 120h dup (?) ;reserve 120h bytes of space
Buff db 250
clen db ?
_chr db 250 dup (?) ;reserve 250 bytes of space for line
.CODE
START:
; initialization
push ds ; iveda Word/Doubleword i steka
sub cx, cx ; subtract
push cx
mov cx, ds ;ds = cx specifically moves the data segment
mov ds, cx ;cx = ds same as above

;user input
lea ax, Buff ;load address
mov ah, insert ;insert into ah
int 21h ;close

; putting length into cx
xor cx, cx
mov cl, clen
mov si, offset clen ;loads offset part

;if line is empty, end
cmp cx, 0 ;compare
;testing if end of the line
je FINISH

;string testing
CHECK:
dec cx ;decrement starting pointer by 1
inc si ;raise starting pointer by 1
cmp cx, 0 ;comparing if empty
je CONT ;jei paskutinis, tai baigiamas ciklas
cmp byte ptr [si], GAP ;2 operands compare
je CHANGE ;if gap found, then off to this cycle to change symbol
jmp CHECK
CHANGE:
mov bl, byte ptr [si+1]
mov [si], bl
jmp CHECK ;returning to cycle
CONT:
; '$' at end of buffer
; vi points at last symbol
inc si
mov bl, ENDL
mov [si], bl

;output onto screen
lea ax, Buff
add ax, 2 ;from the 3'rd byte
mov ah, outsert
int 21h; ;finsihing up, closing

;returning to DOS
FINISH:
mov cx, 4c00h ;exit
int 21h
END START

如果已经回答了类似的问题(我无法通过搜索找到任何内容),我会事先道歉。感谢您的回答。

0 个答案:

没有答案
相关问题