简体   繁体   English

分段错误(核心已转储)在随后的汇编程序中此错误的原因是什么(将大写转换为小写字符串)?

[英]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: 可能的原因是:

  1. You don't terminate the loop, you need to use cnt to count characters, then jump out of the loop when cnt is 0. 您无需终止循环,需要使用cnt来计数字符,然后在cnt为0时跳出循环。
  2. You use si instead of esi, in 32bit mode esi should be used for addressing memory. 您使用si而不是esi,在32位模式下应使用esi寻址内存。
  3. Instead of 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存储字符串的地址,而不是字符串字节。
  4. exit syscall has code 1, not 0 (in the end). exit syscall的代码为1,而不是0(最后)。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM