Assembly 名和姓程序集
我正在解决一个问题,我必须在一个字符串中输入名字和姓氏,用空格分隔,只显示姓氏。我创建了一个我觉得很接近的程序,但它不是一个提示符,而是一个outmsg。我不确定如何提示输入名称,并且只显示最后一个。我不确定我是否只需要改变一件事。代码如下:Assembly 名和姓程序集,assembly,masm,irvine32,Assembly,Masm,Irvine32,我正在解决一个问题,我必须在一个字符串中输入名字和姓氏,用空格分隔,只显示姓氏。我创建了一个我觉得很接近的程序,但它不是一个提示符,而是一个outmsg。我不确定如何提示输入名称,并且只显示最后一个。我不确定我是否只需要改变一件事。代码如下: include irvine32.inc title trial .data outmsg DB "Edward Magruder",0 Space DB ' ',0 len DW 0 .code main proc mov ebx, offse
include irvine32.inc
title trial
.data
outmsg DB "Edward Magruder",0
Space DB ' ',0
len DW 0
.code
main proc
mov ebx, offset outmsg
mov edx, offset outmsg
call writestring
call crlf
sub eax,eax
mov ecx, lengthof outmsg
L2:
mov al,[ebx]
cmp al, Space
je goodToGo
add ebx, 1
loop l2
goodToGo:
add ebx, 1
showChar:
mov al, [ebx]
call writechar
add ebx, 1
cmp al, Space
loop showChar
Exit
main endp
end main
//output
//Edward Magruder
//Magruder
Irvine's生成一个以零结尾的字符串,正如您已经在outmsg
中使用的那样。因此,最初的变化很小:
...
.code
main proc
lea edx, outmsg ; Address of an buffer that receives the string
; ... same as `mov ebx, offset outmsg`
mov ecx, sizeof outmsg ; Maximal number of characters to read
call ReadString
mov ecx, eax ; Return value (EAX): strlen -> ECX for the loop L2
xor eax, eax ; EAX=0 for the loop L2
mov ebx, offset outmsg ; EBX points to outmsg for the loop L2
;mov edx, offset outmsg
;call writestring
;call crlf
;sub eax,eax
;mov ecx, lengthof outmsg
L2:
...
接下来的步骤可能是在输入之前输出文本(“输入名称”),并定义更大的输出消息:
outmsg DB 32 DUP (0) ; Reserve 32 bytes and fill them with 0
有两个空格(“理查德·米尔豪斯·尼克松”)或没有空格(“列宁”)的名字是什么