我正在学习汇编,在这个例子中我想连接来自用户的两个字符串
data segment
str1 db "enter the first string : $"
str2 db "enter the second string : $"
str3 db "output is : $"
arr db 200dup('$')
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
mov ax,@data
mov ds,ax
lea dx,str1
mov ah,09h
int 21h
mov ah,10
lea dx,arr
mov arr,8
int 21h
mov ax,@data
mov ds,ax
lea dx,str2
mov ah,09h
int 21h
mov ah,10
lea dx,arr
mov arr,8
int 21h
mov ax,@data
mov ds,ax
lea dx,str3
mov ah,09h
int 21h
lea dx,arr+2
mov ah,09h
int 21h
mov ax,4c00h
int 21h
input 1 : hello
input 2 : world
output : world
但我希望输出为:
hello world
嗯,你应该稍微研究一下存储单词的内存区域。这是如何运作的:
08 05 68-65 6C 6C 6F 0D 24 24 24 s : $..hello.$$$
08 05 68-65 6C 6C 6F 08 05 77 6F s : $..hello..wo
72 6C 64 0D 24 24 24 24-24 24 24 24 24 24 24 24 rld.$$$$$$$$$$$$
08 05 68-65 6C 6C 6F 20 05 77 6F s : $..hello .wo
72 6C 64 0D 24 24 24 24-24 24 24 24 24 24 24 24 rld.$$$$$$$$$$$$
08 05 68-65 6C 6C 6F 20 77 6F 72 s : $..hello wor
6C 64 24 0D 24 24 24 24-24 24 24 24 24 24 24 24 ld$.$$$$$$$$$$$$
data segment
newline db 13,10,'$'
str1 db "enter the first string : $"
str2 db "enter the second string : $"
str3 db "output is : $"
arr db 200 dup('$')
data ends
dstack segment stack
dw 128 dup(0)
top label word
dstack ends
assume cs:code, ds:data, ss:dstack
code segment
start:
mov ax,data
mov ds,ax
mov ax,dstack
mov ss,ax
mov sp,top
lea dx,str1
mov ah,09h
int 21h
mov ah,10
lea dx,arr
mov arr,8
int 21h
lea dx,newline
mov ah,09h
int 21h
lea dx,str2
mov ah,09h
int 21h
;;;; Buffer mod
lea bx, arr + 1 ; read size of Input 1
xor ax, ax ; ax = 0
mov al, [bx] ; al = input 1 length
add al, 1 ; add byte
add bx, ax ; move to the end of input 1
mov dx,bx ; dx = buffer of Input 2, size + 0dh, chars in buffer, buffer
mov ah,10
mov byte ptr [bx], 8 ; max number of letters
int 21h
lea dx,newline
mov ah,09h
int 21h
mov al,32 ; space between words
mov [bx],al
inc bx ; length of input 2
xor cx,cx ; save in cx
mov cl,[bx]
mov di,bx ; copy from [bx] to [di]
inc bx
moveInput2:
mov al,[bx]
mov [di],al
inc bx
inc di
dec cx
jnz moveInput2
dec bx
mov byte ptr [bx],'$' ; end of texts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
lea dx,str3
mov ah,09h
int 21h
lea dx,arr+2
mov ah,09h
int 21h
mov ax,4c00h
int 21h
code ends
end start