Reputation: 177
I am having a lot of trouble figuring out which register holds the information that I need to output. I have tried byte ptr si, bl, bx with incs and decs, but I just flat out cannot figure out what I need to do to be able to output. At the moment it just doesn't output anything. What I need to output is the input, except replacing all the gaps with the character before it, so "a b c" becomes "aabbc".
Here is the code that I just cannot figure out.
.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
If it is necessary, I will add in the cut out code, I removed it because I think that it is not vital to figuring out the output issues. I massively appreciate your patience with me.
Upvotes: 0
Views: 307
Reputation: 58762
The commented out code should pretty much work, except you add 2 to ax
instead of 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
Upvotes: 1