[英]Segmentation fault(core dumped) What is the reason for this error in following assembly programme(converting uppercase to lowercase string)?
I want to convert a string to a string with all characters in upper case.What causes segmentation fault(core dumped) ? 我想将字符串转换为所有大写字符的字符串。什么导致分段错误(核心转储)? What are reasons for segmentation fault?
细分错误的原因是什么?
OutPut:Enter a Stringsbash: line 1: 9 Segmentation fault (core dumped)
Source: 资源:
%macro accept 2
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 0x80
%endmacro
%macro display 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 0x80
%endmacro
section .data
str1 db "Enter a String";
len1 equ $-str1
cnt db 0
section .bss
str2 resb 20
len2 resb 1
c resb 1
section .text
global _start
_start:
display str1,len1
accept str2,2;
dec al;
mov [cnt],al
mov si,[str2]
up:
mov ch,[si]
mov bl,ch
inc si
cmp bl,61
jna up
cmp bl,73
ja up
mov al,20
sub bl,20
mov [si],bl;
mov eax,0
mov ebx,0;
int 0x80
Possible reasons are: 可能的原因是:
cnt
to count characters, then jump out of the loop when cnt is 0. cnt
来计数字符,然后在cnt为0时跳出循环。 mov si,[str2]
you should use mov esi,str2
, so that esi stores address of your string, not string bytes. mov esi,str2
代替mov si,[str2]
,以便esi存储字符串的地址,而不是字符串字节。 Also you probably meant hexadecimal 0x61 (code for letter a), not decimal 61. Same with 73 and 20. 您也可能是十六进制的0x61(字母a的代码),而不是十进制的61。与73和20相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.