tasm输出问题

时间:2015-12-20 14:27:03

标签: assembly x86 dos tasm

我在确定哪个寄存器包含我需要输出的信息时遇到了很多麻烦。我已尝试使用incs和decs的字节ptr si,bl,bx,但我只是看出来无法弄清楚我需要做什么才能输出。目前它只是没有输出任何东西。我需要输出的是输入,除了用它前面的字符替换所有间隙,所以“a b c”变成“aabbc”。

这是我无法弄清楚的代码。

.MODEL SMALL ;defines memory model
.STACK 100H ;reserves memory space
.DATA
insert equ 0ah
outsert equ 9h
ENDL equ '$'
GAP equ ' '
EMPTY equ ' '
newline db 0ah, 0dh, '$'
;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:
mov     dx, @data               ; perkelti data i registra ax
mov     ds, dx                  ; nustatyti ds rodyti i data segmenta

;user input
lea dx, 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

mov dx, offset newline ;from the 3'rd byte
mov ah, outsert
int 21h; ;finsihing up, closing

;pre-checking
PREP:
dec cx
inc si
cmp byte ptr [si], EMPTY
je PREP
jmp CHECK

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 dx, Buff
;add ax, 2 ;from the 3'rd byte
;mov ah, outsert
;int 21h; ;finsihing up, closing
xor ch, ch
mov cl, clen
mov si, offset _chr
ciklas:
lodsb
mov bx, 2
;al
dec bx
jz FINISH
loop ciklas


;returning to DOS
FINISH:
mov ax, 4c00h ;exit
int 21h

如果有必要,我会添加剪切代码,我将其删除,因为我认为找出输出问题并不重要。我非常感谢你对我的耐心。

1 个答案:

答案 0 :(得分:1)

除非您将{2}加到ax而不是dx,否则注释掉的代码应该可以正常工作:

;output onto screen
lea dx, Buff+2
mov ah, outsert
int 21h; ;finsihing up, closing

;returning to DOS
FINISH:
mov ax, 4c00h ;exit
int 21h