News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Variable number of arguments

Started by bf2, July 25, 2011, 05:03:01 PM

Previous topic - Next topic

bf2

From what I can work out, the reason the stdcall protocol doesn't allow use of a variable number of arguments is that the statement
RET n
does not accept a memory or register operand. So you have to hard-code the number of bytes you are cleaning off the stack, i.e. the number of parameters received.

My question is what is the logic behind such a design? Why did Intel create the RET instruction this way?

More generally, given an instruction, how does the chip manufacturer decide whether to allow register/memory operand or just immediate value?

dedndave

just use RET and balance the stack after the CALL, essentially using the C calling convention
if you like, you may then make a wrapper macro that counts the args, makes the CALL, and balances the stack

ixuta

Quote from: bf2 on July 25, 2011, 05:03:01 PM
More generally, given an instruction, how does the chip manufacturer decide whether to allow register/memory operand or just immediate value?
...The chip manufacturer decides how to "wire" the processor internaly. The more each register is connected to each other register will dictate how complex the chip is and how many transistors are on board. When chip real-estate is limitied and expensive, the chip manufacturer has to decide what kinds of instructions are needed and more likely to be used and which ones aren't. Think of a graph in mathematical terms, a fully connected graph has more paths between vertices than a non fully connected graph. Same a processor that has every register capable of doing any job and an instruction that can take any operand reg,mem,imm has more pathways between its parts; so is a bigger, more expensive processor. In the wee-old days, registers in the processor had specific purposes AX:the accumulator BX:the base register CX:the counting register and DX:the data register; they were each better at their job because they were "wired" that way. But, in some procs all registers are general purpose registers.

bf2

Very informative reply. Thank you.

hutch--

The magic word is OPCODE, an instruction hard wired into the processor, this alone determines what can be processed and what cannot. Behind the MNEMONIC "MOV" is a family of similar OPCODES that determine what registers, memory operands and immediates can be used. This is the same with each family of OPCODE, ADD, SUB, CMP, TEST etc ....

When you try something like,


mov pMem, hMem


It fails for no other reason than there is no OPCODE that will perform this operation. Syntax Error is simply a generalised response at a higher interpreted level.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php