 |
| Author |
Message |
Eviscerate Core
Joined: 17 Jul 2010 Posts: 20 Location: CA |
|
ASM language/ vid drivers |
|
I've been slowly dissecting the VGA and NTSC video drivers lately to better understand how they work, and also to see where I could add some functionality, but assembly language is not my strong suite. I will probably have a lot of video related questions as I keep digging deeper, but my first is a pretty basic one that has me confused:
In C, if you call a user defined function, you jump to that function, run through it, and then return to where you were in your main function. Does branching in ASM work the same way? After you branch, do you return to where you've branched from, or is it a permanent jump to the new function?
Here's one place where I'm confused:
 |
 |
mov #524, W2
cp W0, W2
bra nz, DONE_LINE_TEST
setm _g_CurrentLine
DONE_LINE_TEST:
|
So in the code above, if you're not on line 524, you branch. But what about the case in which you don't branch? What happens after setm _g_CurrentLine?
_________________ - Eviscerate Core |
|
| Fri Jul 30, 2010 6:42 am |
|
 |
necron
Site Admin

Joined: 01 Jan 1970 Posts: 4813
|
|
|
|
Well, in C/C++ when you make a function call, your current state gets stacked and if the compiler sees a return then it restores state and returns to the instruction after the function call. That's a function call. In C, we rarely use GOTO, so everything is done with loops, and conditional branches.
In asm, we have "calls" which push the state (a little) the return address at least, and we have GOTO which is a branch. So, many times you will see tiny little branches over a line or two of code, then when you see a call or jsr these are to functions and expect to return to the caller -- so, you have:
1. jmps -- similar to GOTO, the instruction pointer just goes there, jmps are usually performed no matter what and can go anywhere in address space, no conditional testing.
2. branches - like GOTO, but they have conditions that they branch on, furthermore, usually are "near" meaning you can only branch +-256 bytes, or 16K, etc. some finite distance.
3. calls -- these are used to emulate functions, a call stacks the return address, then jmps to the target, then its your job as the asm programmer to stack the registers, do your function, then restore them and then do a return. Additionally, more advanced processors have calls that stack the registers and status for you, basically they are helping you writing functional languages, so you can save yourself the typing.
But, read a good tutorial on PIC ASM programming, takes a weekend, and ASM is very easy actually, its just VERY detailed.
Andre'
|
|
| Fri Jul 30, 2010 7:30 pm |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|