简体   繁体   中英

gas assembler: segmentation error while reading from keyboard (simple program)

i'm getting the segmentation error while trying running a simple assembly code.... basically i want to keep asking for an input form keybord until the return key is pressed, idk what is causing it since I'm new to gas assembly, could you kindly help me pls?

.section .data
    num:
       .int
.section .text
   .global _start

    _start: 
    leggi:
          movl $3, %eax
          movl $0, %ebx
          leal num, %ecx
          movl $1, %edx
          int $0x80
          movl $10,%edx
          cmp %edx,num
          jne leggi

          movl $1, %eax
          xorl %ebx,%ebx
          int $0x80

I was under the impression that .int allowed you to specify zero or more expressions, and that it would create space for each of those expressions.

With no expressions, it may be allocating zero space, which will probably cause you problems. Possibly, with an empty data section, you'll be then writing into the first byte of the next section, which may well be the write-protected text section.

Have a look at the resulting output and see what it's doing. If that is the problem, you should be able to fix it with:

.int 0

However, you may also want to watch out for the fact that you're reading bytes but using int-sized data in your code. I'd probably be using .byte myself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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