名字和名字汇编

时间:2015-12-17 08:19:15

标签: 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, 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

1 个答案:

答案 0 :(得分:0)

Irvine的ReadString生成一个以零结尾的字符串,因为您已经使用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:
...

接下来的步骤可能是在输入之前输出一个文本(“输入名称”)并使用WriteString来定义更大的outmsg:

outmsg DB 32 DUP (0)        ; Reserve 32 bytes and fill them with 0

有两个空格的名字(“理查德米尔胡斯尼克松”)或没有空格(“列宁”)是什么?