Advertisement

Question about assembly...

Started by March 19, 2000 02:40 AM
18 comments, last by BraveZeus 24 years, 9 months ago
Ok, I have no real background in asm, but I am interested in knowing how functions(or at least function-like design) are implemented, is it using jmp and then another call to a return type statement, or is there something else? This is probably a simple question for someone who has already learned assembly
Chris
Pretty simple, its like this:

func proc near ;this is the function I want to call
(push stuff ;usually a good idea to preserve regs
(blah) ;do stuff
(pop stuff) ;restore the regs
ret ;this returns you

call func ;this calls the function

Later,
The Timdog
Advertisement
Since im not registered i''ll post my questions here
Timdog, you said you used the PROC to make a (sub)routine but if I just want to do like:
Begin:
call Hello
Hello:
mov shit,piss
mov to,here

the how do I do for passing arguments for hello(ex: in C it would be like Hello(int arg)) and when calling it how do you set the arguments???

Is there any way to use structures in ASM, or how to get around that, it would be a pain to not having the variables (for ex to an sprite/pcx-file you better move the header information to a structure or??)

I use TASM 3.1 so the info just must be in DOS-format.
Example code appreciated.
Thanx in advance!

//Freddie
Ok, thanks Timdog, but I still have one question : what is jmp used for, it does just jump to an address in memory and begin execution there, right? Is it just like goto, or something else?
Chris
1) Anonymous - I''ve forgotten how to pass arguments in assembly. Assembly language is good to know, but not exactly my first choice.

2) BraveZeus - Yes, jmp acts like a ''goto''. You''ll want to use jmp (and all its forms) to set up ''if'' and ''switch'' statements in assembly. Something like the following:

cmp ax,bx ;compare ax and bx
je block1 ;if they are equal, jmp to block1
jmp block2 ;otherwise jmp to block2
block1:
(stuff)
jmp endblock (jmp to the end of block structure)
block2:
(stuff)
endblock:

Got it?

Later,
The Timdog


Parameters are passed via the stack.

You can acces them inside the function via the base pointer.

____________________________Mmmm, I''ll have to think of one.
Advertisement
Something like this then:

push X
push Y
call plot

plot:
mov cl,bp
mov ch,bp
.....
do stuff
....

or ?
Nope, more like this:

// Main program
push paramater1
push parameter2
call SomeFunction
add 8, esp

// That last mnemonic removes the parameters
// from the stack, assuming that the parameters
// are 4 bytes each;

// The function would look like this:

function SomeFunction
push ebp // Save old ebp;
mov esp ebp // Put esp in ebp;
// Reserve space for local variables;
// Save nonfree usable registers by pushing them.

// now you can acces the parameters at
ebp + 4
ebp + 8

// Do stuff here...

// Cleanup
pop ebp // Restore ebp;

There is a lot more to do then only this and the +4 and +8 could differ depending on what more you need to store. I suggest you pick up a book on this.

Jaap Suter


____________________________
Mmmm, I''ll have to think of one.
____________________________Mmmm, I''ll have to think of one.
Holy shit, that was really weird, think I rather use macro''s
The multiplication instruction, how does it work?
Is this valid for example:

Macro Plot_X_Y Row, Column, Color
mov ah,Row
mov ch,Column

mul ax,Mode14h_Width // equ!!
add ax,ch
....
ENDM
Does that perform Y*320+x???
Is the result saved in ax? if not were did it go? :D

//Freddie From Sweden
Another thing BTW, I''m trying to make a routine for plotting filled rektangles, and the algoritm is simple, just draw a line from X1 to X2 then jump down to the next row and do so until Y2 equals an speciefied value, but the routine i wrote thosent work, it draws the entire fucking screen..:
mov ax,0013h
int 10h
mov ax,0a000h
mov es,ax
xor ax,ax ; else the screen turns into grey
call cls

mov di,0 ; Start x1 & y1 pos
mov al,4 ; Färg, Röd
mov ch,0 ; Y2
@loop:
mov es:[di],al
cmp di,10 ; X2
je @loop1
inc di
jne @loop
@loop1:
cmp ch,5
je @end1
add di,310
inc ch
jmp @loop
Can someone tell me what''s wrong please ''cos it drives me crazy, the Horz-line and Vert-line worked fine, but not this. the @end1 routine simple waits for a left-button mouse click and if you click it ends and the program reach that so why does it draw the entire screen??
It doesnt matter if you change the values in ch and di either.

//Freddie

This topic is closed to new replies.

Advertisement