On the other hand, how is MASM macro different?
Try doing something like this in C:
include \masm32\MasmBasic\
MasmBasic.inc ;
download.data?
MyByte db ?
MyWord dw ?
MyDw dd ?
MyQw dq ?
MyR4 REAL4 ?
MyR10 REAL10 ?
Init mov ecx,
Chr$("123.456")
; a string to be converted to a number MovVal MyByte, ecx
MovVal MyWord, ecx
mov ecx,
Chr$("123456.789")
MovVal MyDw, ecx
MovVal MyQw, ecx
MovVal MyR4, ecx
MovVal MyR10, ecx
MovVal xmm0, ecx
; xmm0 as integer (default) MovVal f:xmm1, ecx
; xmm1 as float (f:) Dim My
$() ; create a string array (yes, that could be more complicated ;)) For_ ebx=0 To 5
Let My$(ebx)=
Str$("String #%i=", ebx)+
Str$(ebx*MyR4)
; assign some values, e.g. 3*123456.78 PrintLine "[", My$(ebx), "]"
Next push
Val(ecx)
; the simple Val returns eax fild dword ptr [esp]
; get the FPU involved pop eax
;
debug macro - does not trash any regs or flags, can display almost everything...
deb 4, "
Results:", eax, ST(0), MyByte, MyWord, MyDw, MyQw, MyR4, MyR10, xmm0,
f:xmm1
Inkey CrLf$, "--- cute, isn't it?"
Exitend start
Output:
[String #0=0.0]
[String #1=123456.8]
[String #2=246913.6]
[String #3=370370.4]
[String #4=493827.2]
[String #5=617283.9]
Results:
eax 123457
ST(0) 123457.000000000000
MyByte 123
MyWord 123
MyDw 123457
MyQw 123457
MyR4 123456.8
MyR10 123456.789000000000
xmm0 123457
f:xmm1 123456.7890000000P.S.: I liked your wacky macros page -
#define sizeof(x) rand() looks great for bug chasing ;-)
P.P.S.:
Load Windows.inc into a buffer and transform the buffer into a string array.
I suspect this is possible with BSL's bsplit / bsplits / bsplitstr functions but I have not been able to get it working.
Found an
example by Paul Hsieh himself but it fails miserably with loads of error messages :(
However, I got this working; it loads the correct #strings, and the timings are plausible, but I can't figure out how to use the 'tokens' for string operations including printing:
/* called as follows - WinStr is a pointer to a buffer containing Windows.inc: bstring MyArr1 = bfromcstr(WinStr);
rv=ArrayJJ(MyArr1);
*/
int
ArrayJJ(const_bstring src) {
// bstrlib.c, line 2655
struct bstrList* tokens;
int ct;
tokens =
bsplit(src, '\n');
// translates source string to an array
// push 0Ah // linefeed
// push ebx // src
// call bsplit __asm mov ct, ecx;
// returns number of strings (undocumented?)
#if 0
// __asm int 3; // how can we use the array??? // compiles but prints garbage: printf("T0=%s\n", tokens->entry[0]);
printf("T1=%s\n", tokens->entry[1]);
printf("T2=%s\n", tokens->entry[2]);
#endif
return ct;
}