我正在尝试创建一个简单的文本编辑器,但我不确定如何将用户输入保存到字符串中。如何移动和控制每个字符串中的位置?另外,如何使用SI控制何时转到下一个字符串?到目前为止,我有:
matriz:
mov si, 0
mov si, offset direc ; for directions
mov di, 0
mov di, offset fila1 ; [si+0] for 1st row
mov word ptr[si], di
add si, 2
mov di, offset fila2 ; [si+2] for 2nd row
mov word ptr[si], di
add si, 2
mov di, offset fila3 ; [si+4] for 3rd row
mov word ptr[si], di
add si, 2
mov di, offset fila4 ; [si+6] for 4th row
mov word ptr[si], di
add si, 2
mov di, offset fila5 ; [si+8] for 5th row
mov word ptr[si], di
add si, 2
ret
...........................
write:
mov cx, 1
cycle:
mov ah, 2h ; character output
int 10h ; display character in dl
mov ah, 1h ; keyboard input
int 21h ; read character into al
cmp al, 27 ; ESC
je fin
cmp al, 0
je compararSpecialKeys
mov byte ptr [di], al
mov cl, dl ; to not lose value of posX
mov dl, al ; to be able to print
mov ah, 2h ; character output
int 10h ; display character in dl
mov dl, cl
inc dl ; to move a position
mov posX, dl ; update posX
cmp posX, 38 ; border limit
je nextline
inc di
loop cycle
jmp start
ret
nextline:
mov dl, 1
mov posX, dl ;update posX
inc dh
mov posY, dh ;update posY
add si, 2
call write
posX db 1 dup(1) ; dl = posX -> controls column
posY db 1 dup(1) ; dh = posY -> controls row
xlimit dw 38 ; number of columns
ylimit dw 24 ; number of rows
direc db 36 dup(42) ; 42 is ASCII for space
fila1 db 36 dup(42)
fila2 db 36 dup(42)
fila3 db 36 dup(42)
fila4 db 36 dup(42)
fila5 db 36 dup(42)
答案 0 :(得分:1)
.loop:
mov ah, 7
int 21h
cmp al, 27 ; ESC
je finish ; that will call fin
mov ah, 0
int 16h ; for special keys
call comparar
jmp .loop
这部分代码在循环中会做得更好,因为你想要读取多个输入,而不只是一个。此外,comparar
现在在其操作的最后需要ret
。
moveUp:
mov dl, posX ;actualizar coordinates
mov dh, posY
dec dh ; posY --
mov posY, dh
jmp prntCrs ; print cursor
我不确定这不应该是
moveUp:
mov dl, byte [posX] ;actualizar coordinates
mov dh, byte [posY]
dec dh ; posY --
mov byte[posY], dh
jmp prntCrs ; print cursor
将posX
和posY
声明为
posX: db 0
posY: db 0
存储值。