assembly - 为什么输入调用在我的 asm 代码中不起作用?
问题描述
我已尝试使用以下代码以汇编语言进行数据块传输。该代码适用于非重叠案例,但我无法输入输入以获取“计数”值。
section .data
name db 'John' ;initialize name array
name_len equ $-name ;initialize name length
surname db 'Smith' ;initialize surname array
sur_len equ $-surname ;intialize surname length
tot equ name_len + sur_len ;initialize total length
msg1 db "Initial name is: " ;message 1
msg1_len equ $-msg1 ;length of message
msg2 db 0xa,"Non-overlapped transfer: " ;message2
msg2_len equ $-msg2
msg3 db "Overlapped String transfer: "
msg3_len equ $-msg3
endl db 0xa
endlen equ $-endl
steps db 0 ;Stores the value length-count
msg4 db "Enter 1,2 or 3"
msg4_len equ $-msg4
msg5 db "Enter the count "
msg5_len equ $-msg5
section .bss
choice resb 1 ;for non-overlapped or overlapped
a resb 1 ;storing final length in overlapped case
count resb 1 ;Count is the number of letters which are overlapped
section .text
global _start ;linker
_start:
beg:
mov eax,4
mov ebx,1
mov ecx,msg4
mov edx,msg4_len
int 0x80
mov eax,4
mov ecx,endl
mov edx,endlen
int 0x80
mov eax,3
mov ebx,1
mov ecx,choice
mov edx,1
int 0x80
cmp byte[choice],0x33
je exit
cmp byte[choice],0x32
je overcall
cmp byte[choice],0x31
je noncall
noncall:
call non
jmp exit
overcall:
mov eax,4
mov ebx,1
mov ecx,msg5
mov edx,msg5_len
int 0x80
mov eax,3
mov ebx,1
mov ecx,count ;I can't input any value for count in the terminal
mov edx,1
int 0x80
sub byte[count],0x30
mov al,name_len
add al,sur_len
sub al,[count]
mov [a],al
call over
jmp exit
exit:
mov eax,1 ;syscall for exit
int 0x80 ;call kernel
non:
mov eax,4 ;syscall for print
mov ecx,msg1 ;move address of msg1 to ecx
mov edx,msg1_len ;move msg1 length to edx
int 0x80 ;call kernel
mov eax,4 ;syscall for print
mov ecx,name ;move address of name to ecx
mov edx,name_len ;move name length to edx
int 0x80 ;call kernel
mov esi,name ;move address of name to esi
mov edi,surname ;move surname address to edi
add esi,name_len ;add name_length to move to last byte
mov ebx,sur_len ;move length of surname to ebx
up:
mov eax,[edi] ;move character of surname to eax
mov [esi],eax ;move character to last of name
inc esi ;increment esi
inc edi ;increment edi
dec ebx ;decrement count
jnz up ;jumpif not zero to up
mov eax,4 ;syscall for print
mov ecx,msg2 ;move address of name to ecx
mov edx,msg2_len ;move name length to edx
int 0x80 ;call kernel
mov eax,4 ;syscall for print
mov ecx,name ;move address of name to ecx
mov edx,tot ;move total length to edx
int 0x80 ;call kernel
mov eax,4
mov ecx,endl
mov edx,endlen
int 0x80
ret
over:
mov eax,4
mov ecx,msg3
mov edx,msg3_len
int 0x80
xor rax,rax
mov rsi,name
mov rdi,surname
mov al,name_len
sub al,[count]
mov [steps],al
add rsi,rax
mov ecx,sur_len
xor rax,rax
upp:
mov al,[rdi]
mov [rsi],al
inc rsi
inc rdi
dec ecx
jnz upp
mov eax,4
mov ecx,name
mov edx,[a]
int 0x80
mov eax,4
mov ecx,endl
mov edx,endlen
int 0x80
ret
选择选项为 2 后,程序只会打印一些垃圾。
这是输出:
Enter 1,2 or 3
2
Enter the count Overlapped String transfer: JohnSmithInitial name is:
Non-overlapped Smithfer: Overlapped String transfer:
*Enter 1,2 or 3Enter the count 2/�
如果我只是初始化计数值而不是从用户那里接受它,代码就可以正常工作
解决方案
推荐阅读
- google-sheets - 结果排序问题:查询 importrange Vs ArrayFormula(query(TO_TEXT(importrange)
- php - 选择 json 字段等于的位置
- c# - C# 如何使用 EmguCV 去除验证码的噪音?
- python - 使用元组作为标记时更改 matplotlib 的图例中的标记大小
- python - loc() 函数不会读取 Datetime date.today 来拆分 panda DataFrame。(键错误)
- java - FilterInputStream IS-A InputStream 和 HAS-A InputStream
- javascript - 实现多语言时的 SASS Mixin 排版问题
- python - 目标是列表时的Pygame设置音量
- python-3.x - tkinter 中的格式化文本
- java - 检查传感器是否存在并且是否正常工作的可靠方法是什么?