I just started learning assembler and I don’t really understand how function calls work. There is a clearScreen procedure that clears the console. In the code, I call it via call. But then the code

PRINT "x = " call scan_num 

starts to be performed endlessly. That is, when I press Enter after entering the value of x, the program clears the console and asks for the value again. The END line is not displayed. Why it happens? Help solve the problem. Thank you in advance.

 org 100h include 'emu8086.Inc' .data table dw 0, 1, 2 a db ? x db ? .code PRINT "a = " call scan_num mov a, cl clearScreen proc push ax ; зберігаємо результат обчислень у стек mov ax, 03 ; 2 наступні команди очищають консоль int 10h pop ax ; поновлюємо результат обчислення у регістр clearScreen endp PRINT "x = " call scan_num call clearScreen PRINT "END" hlt define_scan_num define_print_num define_print_num_uns END 
  • one
    Instructions are in the code exactly in the order you wrote. since you wrote the procedure in the middle of the code, it is there and when it ends the control falls on the instruction following it, i.e. on print. Call this same jmp, but it still pushes the return address on the stack, you can use it and return to the call point using ret. And for this to work correctly, the function should not be in the middle of the code, but separately. In addition, you should not use hlt, it stops the processor and the machine freezes. - Mike
  • Thank you, figured out - Jack132

0