0

I am practicing conditional jumps based on flags, Below is the program to get 1st -ve number.

While Debugging I am getting below error enter image description here

When code is trying to return from found subroutine then its showing the above info

; chapter -06
; find first negative number

.386
.model flat,stdcall
.stack 4096

.data
slist SWORD 0,1,2,3,-9,10,20

ExitProcess PROTO,dwExitCode:DWORD

.code

main PROC
    
    mov ecx,LENGTHOF slist
    mov esi,OFFSET slist
    mov ebx,0
    L1:
        mov eax,0
        add ax,[esi]     ; if result is negative PL(sign flag will be set PL=1)
        js found
        pushfd           ; backup 32 bit eflag to runtime stack
        add esi,4        ; jump to next signed number in slist
        popfd            ; restore EFLAGS
        LOOP L1
    jns notfound
    INVOKE ExitProcess,0

main endp

found PROC
    mov bx,[esi]  ; update ebx with 1st negative number found
    mov ecx,0     ; set ECX to 0 to exit loop
    ret
found endp

notfound PROC
    mov ebx,0
    ret
notfound endp

end main
Hackaholic
  • 19,069
  • 5
  • 54
  • 72
  • 1
    If you are going to use `ret` to return, then you must use `call` to call it. Using `ret` is going to return to the caller of `main`, which is no one. – David Wohlferd Jul 11 '22 at 06:47
  • @DavidWohlferd ahh my bad got it thanks. ret must be used with call – Hackaholic Jul 11 '22 at 07:05
  • Alternately you can move the code for found/notfound into main and just jump to the code you want. But using jump to get there and ret to get back isn't going to work. – David Wohlferd Jul 11 '22 at 18:05

0 Answers0