【发布时间】:2011-05-08 14:57:38
【问题描述】:
我有一个(看似)简单的问题,要读取一个字符串并使用基于 x86 中断的程序集再次打印出来。我遇到的问题是访问已正确读取的字符串。变量 - input db 20, 0, " " 是我的初始字符串。在我调用输入中断之后,0 现在应该保存字符串的长度,当我调用打印中断时,我需要存储并传递给cx。 20 是输入的最大长度。我最终遇到了两个问题 - 如何访问字符串的长度(我使用的是任意数字,要么将其缩短或在结束后打印垃圾),以及如何在没有数字位的情况下访问字符串开始?任何帮助表示赞赏,我的尝试是:
(我在win 7 32位下使用tasm & Tlink,也在dos box emulation下使用)
;7. Read in a String of characters and Print the string back out.
.model small
.stack 100h
.data
colour db 00001111b
input db 20, 0, " "
strlen dw 20; this should be ?
.code
main:
call initsegs
call readstring
call printstring
call exit
PROC printstring
push ax bx cx dx bp
mov ah, 13h ; int 13h of 10h, print a string
mov al, 1 ; write mode: colour on bl
mov bh, 0 ; video page zero
mov bl, colour; colour attribute
mov cx, strlen; getting this is the problem
mov dh, 10; row
mov dl, 10; column
mov bp, offset input ; es:bp needs to point at string..this points to string but includes its max and length at the start
int 10h;
pop bp dx cx bx ax
ret
ENDP printstring
PROC readstring
push ax dx
mov ah, 0ah ; function a of 21h - read a string
mov dx, offset input ; reads string into DS:DX so DX needs be offset of string variable
int 21h ; call the interrupt
;mov strlen ....something
pop dx ax
ret
ENDP readstring
PROC exit
mov ah, 4ch
INT 21h
RET
ENDP Exit
PROC initsegs
push ax
mov ax, @DATA
mov ds, ax
mov es, ax
pop ax
RET
ENDP initsegs
end main
【问题讨论】: