Вопрос

I have reserved bytes that are modified by my assembly routine.

I was using pusha /* did my job */ and then popa but it results in segmentation fault.

If I replace the pusha and popa with push eax push ecx /* do my job */ pop ecx pop eax it works fine.

But why do I get this seg fault? How is it related to pusha?

Below is a part of my code. Here, I only use two out of eight registers. If I need to use eight in my routine, will I need to push and pop each register? Is there no way to do pusha and popa but keeping buf?

main:
   pusha
    mov eax,10
.AGAIN:
    cmp eax,0
    je .END
    mov [buf + ecx],'.'
    inc ecx
    dec eax
    jmp .AGAIN
.END:
    mov [buf + ecx],0
    mov ebp,buf
    call puts
    popa
    ret

don't give a seg fault:

main:
    push eax
    push ecx
    mov eax,10
.AGAIN:
    cmp eax,0
    je .END
    mov [buf + ecx],'#'
    inc ecx
    dec eax
    jmp .AGAIN
.END:
    mov [buf + ecx],0
    mov ebp,buf
    call puts
    pop ecx
    pop eax
    ret

buf is defined as:

segment readable writeable
buf rb 12

Это было полезно?

Решение

Pusha/popa save the 16-bit registers (AX, BX, CX, DX, SP, BP, SI, DI). You are changing the 32 bit registers EAX and ECX so use the 32 bit equivalent: pushad and popad.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top