You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fastcall is used to indicate that an assembly function should be jumped into with registers already set.
3
+
`FastCall` is used to indicate that a [`SUB`](sub.md) or [`FUNCTION`](function.md) will follow the _FastCall_ Calling
4
+
Convention. In this convention, the 1<sup>st</sup> parameter of the function will come in the registers as follows:
4
5
5
-
* If the function takes a Byte (or uByte) parameter, then the A register will be set with this parameter.
6
-
* If it takes an Integer (or uInteger) parameter, then the HL register will be set with the value of that parameter on entry to the function.
7
-
* If it takes a Long (or uLong), or fixed parameter, then the DE and HL registers will hold the 32 bit value of the parameter.
8
-
* If it takes a float type parameter, then the registers C, DE and HL will hold the five bytes for that value.
6
+
* If the function takes a `Byte` (or `UByte`) parameter, then the `A` register will be set with this parameter.
7
+
* If it takes an `Integer` (or `UInteger`) parameter, then the `HL` register will be set with the value of that parameter
8
+
on entry to the function.
9
+
* If it takes a `Long` (or `ULong`), or fixed parameter, then the `DE` and `HL` registers will
10
+
hold the 32bit value of the parameter, where `HL` holds the lower 16 bits and `DE` the higher one.
11
+
* If it takes a `Float` type parameter, then the registers C, DE and HL will hold the five bytes for that value.
12
+
Here, `C` is the exponent (excess 127), and `DEHL` the mantissa, being `DE` the highest 16 bits and `HL` the lower ones.
9
13
10
14
Return is automatic based on the function return type in the same way:
11
-
*8 bit returns should be in the A register
12
-
*16 bit returns should be in HL
13
-
*32 bit returns should be in DEHL
14
-
*40 bit FLOAT returns should be in CDEHL.
15
+
*8bit returns should be in the A register
16
+
*16bit returns should be in HL
17
+
*32bit returns should be in DEHL
18
+
*40bit FLOAT returns should be in CDEHL.
15
19
16
-
Fastcall should ONLY be used with functions that take a single parameter. If you use more than one parameter, you'll have to deal with the stack (SP register) and restore it to the previous it had before your function was called.
20
+
Strings are a 16bit `UInteger` pointer, hence the `HL`register will be used (both for parameters and return values)
17
21
18
-
**Example:**
22
+
`FastCall` should ONLY be used with functions that take a single parameter. If you use more than one parameter, the remaining
23
+
parameters will come in the stack. Upon return, you will have to deal with the stack (SP register) and restore it to the
24
+
state it had prior your function was called.
19
25
20
-
```
26
+
When entering the function, the stack will be as follows:
27
+
28
+
*[SP + 00]: Return address. Top of the stack (16 bits)
29
+
*[SP + 02]: 2<sup>nd</sup> parameter (if any)
30
+
31
+
32
+
## Example
33
+
34
+
```vbnet
21
35
FUNCTIONFASTCALLwhatLetter(AasuByte)asuByte
22
-
Asm
23
-
PROC
24
-
LOCAL DATA, START
25
-
JP START
26
-
DATA: DEFB "A Man, A Plan, A Canal, Panama"
27
-
START: LD HL,DATA
28
-
LD D,0
29
-
LD E,A
30
-
ADD HL,DE
31
-
LD A,(HL)
32
-
ENDP
33
-
End Asm
36
+
Asm
37
+
PROC
38
+
LOCALDATA,START
39
+
JPSTART
40
+
DATA:DEFB"A Man, A Plan, A Canal, Panama"
41
+
START:LDHL,DATA
42
+
LDD,0
43
+
LDE,A
44
+
ADDHL,DE
45
+
LDA,(HL)
46
+
ENDP
47
+
EndAsm
34
48
ENDFUNCTION
35
49
```
36
50
@@ -40,3 +54,7 @@ The above function, when called with `whatLetter(<value>)` will return the `<val
40
54
### Notes
41
55
* Note that the A register already contains `<value>` when the inline assembly is reached.
42
56
* Note that we do NOT need to put a ret opcode on the end of the assembly. The compiler will do that for us.
0 commit comments