Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8086 assembler parameter passing question

Status
Not open for further replies.

lucky6969b

Member level 2
Member level 2
Joined
Oct 14, 2009
Messages
49
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,639
Hello,
The following code is copied from a book.....

Code:
   1. FontInfo proc FAR C PUBLIC USES DS SI, buf:FAR PTR, choice:byte
   2. ;;;;;;;;;;;;;;;;;;;;


FAR, C, PUBLIC seem to be macros.
How do I pass parameters to the subroutine using the name 'buf'?
I don't want to use global variables. What should I do?
The book is very incomplete
Thanks
 

I would avoid using those directives. They are assembler specific (i.e. accepted in TASM or MASM but not in NASM or viceversa).

Ultimately, parameter passing is done by putting addresses on the stack (PUSH and POP are the most common opcodes for this purpose).

If your subroutines call or are called by other routines, you may want to stick to their parameter passing convention, the most popular being the Pascal and C conventions. Otherwise you have the freedom to implement your own convention as long as your entire program is consistent.

Hope this helps.

Iñaki Viggers
 

This takes me back a few years... If my memory is still working:

Most assembler will accept them, including Intel's.

FAR = the routine may not be in the current segment so create the full address for it, not just the offset.
C = (I think) the order of parameters follows the 'C' convention rather than the Pascal one. (reversed order)
PUBLIC = the routine is available anywhere including to other modules.

Pass parameter using FontInfo xxx, yyy where xxxx is a far pointer and yyy is a byte value.

Brian.
 
I seem to recall 2 popular methods for passing parameters and one less popular.

If there were only 1 or 2 parameters, then they'd usually be put in registers (and part of the function's definition was which parameters would be passed in which registers).
Where there was more data to pass, then a pointer to an array of data would be passed in a register (usually a global address in a register-pair for conformity, but we didn't always conform!). If neccessary, more than one array of data could be passed by more than one register (or register-pair).
The unpopular method was to use the stack, POP-ing data onto the stack in a defined sequence. This seemed to be more popular with system-wide functions, and is probably the most efficient method, though can be terrible to debug if the stack pointer isn't managed properly (eg if exceptions don't return the stack pointer to the same state as normal operation).

Yes, it was all a long time ago!
 

DXNewcastle you are right also long time ago one would push and pop the stack with fuction call's Jeez I feel so old!
 
Hi lucky6969b
I agree with all the replies given to you.
May I ask a question Is it mandatory to use TurboC for your purpose?
Well I Like that compiler and learnt C on that. But Now 8088/8086 Based PC are really Vintage.
Why not use GCC on Linux or even On Windows if you like in that way.

HiDXNewcastle
The pass by register I guess is used to call a subroutine like thing I guess, like GOSUB in BASIC and pascal subroutine call.
Am I right? If you can clarify it will be great.
 

The pass by register I guess is used to call a subroutine like thing I guess, like GOSUB in BASIC and pascal subroutine call.
Am I right? If you can clarify it will be great.
I think we're using the different terminology of different compilers and languages to describe the same thing. There is only one operation being discussed here, whether we call it a procedure, subroutine, function, software interrupt, call, global function, library function etc. They all use the very special technique of placing the Instruction Pointer to the code being executed onto the stack and all are used in conjunction with a set of Return instructions which take a value from the stack and put it into the Instruction Pointer.

Which ever language you use and whichever terminology you use, that's what they all do.
Passing parameters is something else you do - it only appears that parameter passing is connected with procedures, subroutines etc because we do them at the same time (and if using the stack we must do it in a very orderly and precise manner to ensure that the Instruction Pointer is POPed from the stack correctly). Actually, different compilers can, and do, pass parameters in different ways, though not with as much flexibility as the Assembly Coder or Machine Code writer!
I believe that the use of registers is the most efficient method for very simple functions (eg convert a single character from lower case to upper case) - to use the stack or an indirect pointer to the data simply wastes processing clock cycles. Conversely, using the stack is the most uniform manner of writing code that is consistent and adaptable, but sadly it can be the least efficient in processing time and for simple functions within the heavily used code of an OS or main loop of a small controller, can create conflicts with interrupt handling.
There are many challenges facing Compiler writers, and many of these are trade-offs such as speed vs consistency which is why heavily used code is frequently written at assembly level, to hone it down to the bare minimum of instruction cycles and using the most efficient technique for moving data for each circumstance.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top