I have to pass a char as a parameter using the stack, but the stack doesn't allow anything smaller than 16bits. So I put a char on a 16bit register, push it into the stack. But how do i get the char from my function in order to work with it? I know my register sizes are incorrdect in the code I posted b/c Im not sure how to do this. can anybody help me?


program program13;
#include( "stdlib.hhf" );
static
myChar: byte;
number:int32;
counter:int16;
iAddress:int32;
procedure myFunction(aChar:byte;counterx:int16);@nodisplay;@noframe;


begin myFunction;
pop(iAddress);
pop(counterx);
pop(aChar);


push(iAddress);
ret();
end myFunction;


begin program13;
stdout.put("Gimme the starting letter: ");
stdin.get(myChar);
//mov(myChar,dx);
stdout.put("Gimme the desired height: ");
//stdin.getd();

push(dx);
push(eax);

call myFunction;

end program13;

Recommended Answers

All 7 Replies

You'll need to check your compiler's documentation. If you are using gcc, you can compile with the -S (that's a capital S) option to test some assembly code and look for yourself:

char foo( char c ) {
  return c +1;
  }
int main() {
  return foo( 0 );
  }

Using gcc -S foo.c gets you an assembly file you can look to see how _foo works.

I think (but I'm not sure) that most compilers will push it as a machine word, and just use the low byte.

Hope this helps.

can you explan this example

I'm sorry. My brain must have failed me when I posted last. I thought you were trying to interface with a C function.

What language are you trying to use?

im using assembly language

Can you be less specific?

Hey, I'm sorry. Let me be a little more helpful.

If the stack only permits word values, put your char in the low-order byte of a word and push it on the stack.

When you are in your proc, access the word on the stack containing your char, and just use the low-order byte in the routine.

It looks to me like you are programming on an x86. To return a byte, just put your return value in AL and return as usual.

Hope this helps.

yeah I figured it out and that's exactly how I did it. Thanks for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.