|
15 | 15 | (((x) & 0xff000000) >> 24))
|
16 | 16 |
|
17 | 17 | %define htons(x) ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8))
|
| 18 | + |
18 | 19 | %define ip(a,b,c,d) htonl(a << 24 | b << 16 | c << 8 | d) ; ip(127,0,0,1)
|
| 20 | + |
| 21 | +%define htonx(x) \ |
| 22 | + %if __BITS__==16 \ |
| 23 | + htons(x) \ |
| 24 | + %elif __BITS__==32 \ |
| 25 | + htonl(x) \ |
| 26 | + %elif __BITS__==64 \ |
| 27 | + htonq(x) \ |
| 28 | + %elif \ |
| 29 | + %error "__BITS__ is not 16, 32 or 64" \ |
| 30 | + %endif |
| 31 | + |
| 32 | +%macro str_null_check 1 |
| 33 | + %assign word_length __BITS__/8 |
| 34 | + %strlen len_arg %1 |
| 35 | + %if len_arg % word_length!=0 |
| 36 | + %fatal "Make string a multiple of the word length" |
| 37 | + %endif |
| 38 | +%endmacro |
| 39 | + |
| 40 | +%macro str_null_check 2 |
| 41 | + %assign word_length %2/8 |
| 42 | + %strlen len_arg %1 |
| 43 | + %if len_arg % word_length!=0 |
| 44 | + %fatal "Make string a multiple of the word length" |
| 45 | + %endif |
| 46 | +%endmacro |
| 47 | + |
| 48 | + ;; The PUSH_STRING macros don't null terminate the string |
| 49 | + ;; arguments must be known at assemble time |
| 50 | + |
| 51 | + |
| 52 | +%macro PUSH_STRING 2 ;string, bitcount |
| 53 | + str_null_check %1 %2 |
| 54 | + %assign word_length %2/8 |
| 55 | + %strlen string_length %1 |
| 56 | + %assign num_pushes string_length/word_length |
| 57 | + %assign index string_length |
| 58 | + %rep num_pushes |
| 59 | + %substr slice %1 index-word_length+1,word_length |
| 60 | + %assign index index-word_length |
| 61 | + push slice |
| 62 | + %warning push slice |
| 63 | + %endrep |
| 64 | +%endmacro |
| 65 | + |
| 66 | +%macro PUSH_STRING 1 ;string |
| 67 | + str_null_check %1 |
| 68 | + %assign word_length __BITS__/8 |
| 69 | + %strlen string_length %1 |
| 70 | + %assign num_pushes string_length/word_length |
| 71 | + %assign index string_length |
| 72 | + %rep num_pushes |
| 73 | + %substr slice %1 index-word_length+1,word_length |
| 74 | + %assign index index-word_length |
| 75 | + push slice |
| 76 | + %warning push slice |
| 77 | + %endrep |
| 78 | +%endmacro |
| 79 | + |
19 | 80 |
|
0 commit comments