program NewFeatures {
section module {
}
section data {
int rax = 0
int rbx = 0
int rcx = 0
int rdx = 0
int rsi = 0
int rdi = 0
int r8 = 0
int r9 = 0
int r10 = 0
string str_0 = ""
string str_1 = "--- with statement ---"
string str_2 = "a: x="
string str_3 = " y="
string str_4 = "b: x="
string str_5 = "a after add: x="
string str_6 = "--- in operator ---"
string str_7 = " is odd (in set)"
string str_8 = " is NOT in the odd set"
string str_9 = "grade passes (A/B/C)"
string str_10 = "grade fails (D/F)"
string str_11 = "classifying 1..15:"
string str_12 = " -> prime"
string str_13 = " -> composite"
string str_14 = " -> one"
string str_15 = "--- goto / label ---"
string str_16 = "attempt "
string str_17 = "done after "
string str_18 = " attempts"
string str_19 = "jumping over middle block..."
string str_20 = "this line is never reached"
string str_21 = "landed at label 20, skipped label 30"
string str_22 = "--- doubled-quote strings ---"
string str_23 = "it's a beautiful day"
string str_24 = "she said 'hello world'"
string str_25 = "can't stop, won't stop"
string str_26 = "apostrophe test: o'clock"
string fmt_int = "%lld "
string fmt_str = "%s "
string newline = "\n"
ptr pt = null
ptr player = null
ptr DemoWith_a = null
ptr DemoWith_b = null
int DemoIn_n = 0
int DemoGoto_retry = 0
}
section code {
start:
alloc pt, 16, 1
alloc player, 24, 1
call PROC_DemoWith
print fmt_str, str_0
print newline
call PROC_DemoIn
print fmt_str, str_0
print newline
call PROC_DemoGoto
print fmt_str, str_0
print newline
call PROC_DemoStrings
free pt
free player
done
function PROC_DemoWith:
alloc DemoWith_a, 16, 1
alloc DemoWith_b, 16, 1
print fmt_str, str_1
print newline
store 3, DemoWith_a, 0, 1
store 7, DemoWith_a, 8, 1
load rbx, DemoWith_a, 0, 1
mov rcx, rbx
mul rcx, 2
store rcx, DemoWith_b, 0, 1
load rdx, DemoWith_a, 8, 1
mov rsi, rdx
mul rsi, 2
store rsi, DemoWith_b, 8, 1
print fmt_str, str_2
load rdi, DemoWith_a, 0, 1
print fmt_int, rdi
print fmt_str, str_3
load r8, DemoWith_a, 8, 1
print fmt_int, r8
print newline
print fmt_str, str_4
load r9, DemoWith_b, 0, 1
print fmt_int, r9
print fmt_str, str_3
load r9, DemoWith_b, 8, 1
print fmt_int, r9
print newline
load r9, DemoWith_a, 0, 1
load r10, DemoWith_b, 0, 1
add r9, r10
store r9, DemoWith_a, 0, 1
load r9, DemoWith_a, 8, 1
load r10, DemoWith_b, 8, 1
add r9, r10
store r9, DemoWith_a, 8, 1
print fmt_str, str_5
load r9, DemoWith_a, 0, 1
print fmt_int, r9
print fmt_str, str_3
load r9, DemoWith_a, 8, 1
print fmt_int, r9
print newline
PROC_END_DemoWith:
free DemoWith_a
free DemoWith_b
ret
function PROC_DemoIn:
print fmt_str, str_6
print newline
mov DemoIn_n, 5
cmp DemoIn_n, 1
je IN_FOUND_2
cmp DemoIn_n, 3
je IN_FOUND_2
cmp DemoIn_n, 5
je IN_FOUND_2
cmp DemoIn_n, 7
je IN_FOUND_2
cmp DemoIn_n, 9
je IN_FOUND_2
mov rbx, 0
jmp IN_END_3
IN_FOUND_2:
mov rbx, 1
IN_END_3:
cmp rbx, 0
je ELSE_0
print fmt_int, DemoIn_n
print fmt_str, str_7
print newline
jmp ENDIF_1
ELSE_0:
print fmt_int, DemoIn_n
print fmt_str, str_8
print newline
ENDIF_1:
mov DemoIn_n, 4
cmp DemoIn_n, 1
je IN_FOUND_6
cmp DemoIn_n, 3
je IN_FOUND_6
cmp DemoIn_n, 5
je IN_FOUND_6
cmp DemoIn_n, 7
je IN_FOUND_6
cmp DemoIn_n, 9
je IN_FOUND_6
mov rcx, 0
jmp IN_END_7
IN_FOUND_6:
mov rcx, 1
IN_END_7:
cmp rcx, 0
je ELSE_4
print fmt_int, DemoIn_n
print fmt_str, str_7
print newline
jmp ENDIF_5
ELSE_4:
print fmt_int, DemoIn_n
print fmt_str, str_8
print newline
ENDIF_5:
mov DemoIn_n, 3
cmp DemoIn_n, 1
je IN_FOUND_10
cmp DemoIn_n, 2
je IN_FOUND_10
cmp DemoIn_n, 3
je IN_FOUND_10
mov rdx, 0
jmp IN_END_11
IN_FOUND_10:
mov rdx, 1
IN_END_11:
cmp rdx, 0
je ELSE_8
print fmt_str, str_9
print newline
jmp ENDIF_9
ELSE_8:
print fmt_str, str_10
print newline
ENDIF_9:
print fmt_str, str_11
print newline
mov DemoIn_n, 1
FOR_12:
cmp DemoIn_n, 15
jg ENDFOR_13
cmp DemoIn_n, 2
je IN_FOUND_17
cmp DemoIn_n, 3
je IN_FOUND_17
cmp DemoIn_n, 5
je IN_FOUND_17
cmp DemoIn_n, 7
je IN_FOUND_17
cmp DemoIn_n, 11
je IN_FOUND_17
cmp DemoIn_n, 13
je IN_FOUND_17
mov rsi, 0
jmp IN_END_18
IN_FOUND_17:
mov rsi, 1
IN_END_18:
cmp rsi, 0
je ELSE_15
print fmt_int, DemoIn_n
print fmt_str, str_12
print newline
jmp ENDIF_16
ELSE_15:
cmp DemoIn_n, 4
je IN_FOUND_21
cmp DemoIn_n, 6
je IN_FOUND_21
cmp DemoIn_n, 8
je IN_FOUND_21
cmp DemoIn_n, 9
je IN_FOUND_21
cmp DemoIn_n, 10
je IN_FOUND_21
cmp DemoIn_n, 12
je IN_FOUND_21
cmp DemoIn_n, 14
je IN_FOUND_21
cmp DemoIn_n, 15
je IN_FOUND_21
mov rdi, 0
jmp IN_END_22
IN_FOUND_21:
mov rdi, 1
IN_END_22:
cmp rdi, 0
je ELSE_19
print fmt_int, DemoIn_n
print fmt_str, str_13
print newline
jmp ENDIF_20
ELSE_19:
print fmt_int, DemoIn_n
print fmt_str, str_14
print newline
ENDIF_20:
ENDIF_16:
FOR_CONTINUE_14:
add DemoIn_n, 1
jmp FOR_12
ENDFOR_13:
PROC_END_DemoIn:
ret
function PROC_DemoGoto:
print fmt_str, str_15
print newline
mov DemoGoto_retry, 0
GOTO_10_23:
add DemoGoto_retry, 1
print fmt_str, str_16
print fmt_int, DemoGoto_retry
print newline
cmp DemoGoto_retry, 3
jge ELSE_24
jmp GOTO_10_23
ELSE_24:
print fmt_str, str_17
print fmt_int, DemoGoto_retry
print fmt_str, str_18
print newline
print fmt_str, str_19
print newline
jmp GOTO_20_28
GOTO_30_29:
print fmt_str, str_20
print newline
GOTO_20_28:
print fmt_str, str_21
print newline
PROC_END_DemoGoto:
ret
function PROC_DemoStrings:
print fmt_str, str_22
print newline
print fmt_str, str_23
print newline
print fmt_str, str_24
print newline
print fmt_str, str_25
print newline
print fmt_str, str_26
print newline
PROC_END_DemoStrings:
ret
}
}