flat assembler
Message board for the users of flat assembler.
Index
> Main > [stack issues] What's wrong with this code ? |
Author |
|
majidkamali1370 29 Dec 2011, 14:17
Hi.
I recently found a C program that draws pixels on the screen. I wrote (converted) that program with FASM but it has some errors and causes CPU exceptions but I don't know what is the problem. please check. Thanks
|
|||||||||||
29 Dec 2011, 14:17 |
|
majidkamali1370 29 Dec 2011, 16:45
I didn't understand. You mean I use two pop instructions to get function parameters, because first is waste?
Code: push % ; color = current loop counter call plot_pixel_slow ; call Draw function --->(CPU pushed the return address) ;... plot_pixel_slow: pop ax ; Move color to al --->(pops the return address) pop ax ; <-- You mean this? mov ah, WRITE_DOT ; Move 0x00 to ah pop dx ; Y position of pixel --->(pops the color) |
|||
29 Dec 2011, 16:45 |
|
revolution 29 Dec 2011, 17:17
You have no choice, the CPU will push the return address so you must find a way to skip that to access your parameters. Usually the BP register can be used with the ret n instruction.
Code: push % ; X = current loop counter push % ; Y = current loop counter push % ; color = current loop counter call plot_pixel_slow ; call Draw function --->(CPU pushes the return address) ;... plot_pixel_slow: push bp ; save bp mov bp,sp mov ax,[bp+4] ; Move color to al mov ah, WRITE_DOT mov dx,[bp+6] ; Y position of pixel --->(pops the color) mov cx,[bp+8] ; X position of pixel --->(pops the Y value) int VIDEO_INT leave ret 6 ; pop all parameters off the stack and return |
|||
29 Dec 2011, 17:17 |
|
majidkamali1370 29 Dec 2011, 19:14
Thank you, but would you explain your code please? why you add 4 with bp for the first parameter?
BTW, the screen closes fast. How can I stop it in a period of time or wait for key press? Thanks |
|||
29 Dec 2011, 19:14 |
|
revolution 29 Dec 2011, 19:25
majidkamali1370 wrote: why you add 4 with bp for the first parameter? |
|||
29 Dec 2011, 19:25 |
|
majidkamali1370 29 Dec 2011, 19:37
Thank you.
|
|||
29 Dec 2011, 19:37 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.