Abstracted assembler
From ScienceZero
Contents
Open questions
- What is the default data size, 32 or 64 bit?
- How to specify SIMD and floating-point operations?
- What is the simplest type system that will work?
Language features
bit slicing
index-index a = b.[10..2] index-count a = b.[10,2] index bit = n.[index]
Common symbols
+ - * / < > <= >= <> & and | or ^ eor bic orn eon not << lsl >> lsr >>> asr >|> ror
Built in functions
clz count leading zeros cls count leading signs rbit mirror bits rev swap endian cnt population count cset conditionally set 0 or 1 csetm conditionally set 0 or -1
Program flow
call return again exit bcc while dowhile for for x for x = 1 to y if then else
Conditional
a = cond ? val1 : val2 b = <eq> ? x+1 : y (eq) |eq| <a+b:cs> a = b + c
Memory access
[addr].32 = 0 b = [addr].s16 b = [addr1 + addr2].s16 arr[idx].64 = [addr2] arr[idx]!64 = [addr2] Increment idx by 8
Data structures
String Array BitArray List Hastable Set Tree
Memory manager
Examples
Print value in hexadecimal
toHexStringNLZ: clz x11,x0 sub x11,x11,#64 subs x1,x1,x11,asr #2 cinc x1,x1,eq strb wzr,[x1] .loop: ubfx x10,x0,#0,#4 cmp x10,#9 add x10,x10,#'0' add x11,x10,#7 csel x11,x10,x11,ls strb w11,[x1,#-1]! lsr x0,x0,#4 cbne x0,.loop ret
tohhex adr number leadingZeros = clz number remainingBits = 64 - leadingZeros remainingDigits = remainingBits / 4 adr = adr + remainingDigits if remainingDigits = 0 adr += 1 [adr].8 = 0 dowhile number <> 0 digit = number.[3..0] number = number >> 4 if digit <= 9 digit = digit + '0' else digit = digit + '0' + 7 adr -= 1 [adr].8 = digit