program FeaturesDemo {
section module {
std
}
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
ptr _tmpptr0 = null
ptr arg0 = null
ptr arg1 = null
string str_0 = "=== MXVM Extended Pascal Features Demo ==="
string str_1 = "--- Doubled-Quote Strings ---"
string str_2 = "It's a beautiful day!"
string str_3 = "She said, 'Hello, World!'"
string str_4 = "Can't stop, won't stop."
string str_5 = "--- Enumerated Types ---"
string str_6 = "Season "
string str_7 = " = "
string str_8 = "ord(Summer) = "
string str_9 = "succ(Spring) = "
string str_10 = "pred(Winter) = "
string str_11 = "North + inc = "
string str_12 = " (East)"
string str_13 = "East + inc(2) = "
string str_14 = " (West)"
string str_15 = "West - dec = "
string str_16 = " (South)"
string str_17 = "Direction degrees: N="
string str_18 = " E="
string str_19 = " S="
string str_20 = " W="
string str_21 = "--- In Operator (Set Membership) ---"
string str_22 = "Warm seasons:"
string str_23 = " "
string str_24 = " is warm"
string str_25 = " is cold"
string str_26 = "Classifying 1-20:"
string str_27 = ":prime "
string str_28 = ":composite "
string str_29 = "--- Variant Records ---"
string str_30 = "Circle"
string str_31 = " at ("
string str_32 = ","
string str_33 = ") radius="
string str_34 = " area~"
string str_35 = "Rectangle"
string str_36 = ") "
string str_37 = "x"
string str_38 = " area="
string str_39 = "Triangle"
string str_40 = ") base="
string str_41 = "--- With Statement + Variant Records ---"
string str_42 = "Alice"
string str_43 = "Bob"
string str_44 = "--- Result Variable ---"
string str_45 = "Max(42, 17) = "
string str_46 = "Max(3, 99) = "
string str_47 = "Clamp(150, 0, 100) = "
string str_48 = "Clamp(-5, 0, 100) = "
string str_49 = "Clamp(50, 0, 100) = "
string str_50 = "--- Goto / Label ---"
string str_51 = " "
string str_52 = "Counted to 5 using goto"
string str_53 = "=== All features demonstrated successfully ==="
string str_54 = "Employee #"
string str_55 = ": "
string str_56 = " Hourly: $"
string str_57 = "/hr x "
string str_58 = " hrs = $"
string str_59 = " Salaried: $"
string str_60 = "/year"
string str_61 = "Spring"
string str_62 = "Summer"
string str_63 = "Autumn"
string str_64 = "Winter"
string str_65 = "Unknown"
string fmt_int = "%lld "
string fmt_str = "%s "
string newline = "\n"
int s = 0
ptr shape1 = null
ptr shape2 = null
ptr shape3 = null
ptr emp1 = null
ptr emp2 = null
int n = 0
int count = 0
ptr InitShape_s = null
int InitShape_nx = 0
int InitShape_ny = 0
ptr InitShape_shapeName = null
ptr PrintEmployee_e = null
int SeasonName_s = 0
ptr __funcret_SeasonName = null
int DirectionDegrees_d = 0
int __funcret_DirectionDegrees = 0
ptr ShapeArea_s = null
int __funcret_ShapeArea = 0
int Max_a = 0
int Max_b = 0
int __funcret_Max = 0
int Clamp_val = 0
int Clamp_lo = 0
int Clamp_hi = 0
int __funcret_Clamp = 0
}
section code {
start:
alloc shape1, 56, 1
alloc shape2, 56, 1
alloc shape3, 56, 1
alloc emp1, 40, 1
alloc emp2, 40, 1
print fmt_str, str_0
print newline
print newline
print fmt_str, str_1
print newline
print fmt_str, str_2
print newline
print fmt_str, str_3
print newline
print fmt_str, str_4
print newline
print newline
print fmt_str, str_5
print newline
mov s, 0
FOR_0:
cmp s, 3
jg ENDFOR_1
print fmt_str, str_6
print fmt_int, s
print fmt_str, str_7
mov rbx, s
call FUNC_SeasonName
mov _tmpptr0, arg0
print fmt_str, _tmpptr0
print newline
FOR_CONTINUE_2:
add s, 1
jmp FOR_0
ENDFOR_1:
print fmt_str, str_8
print fmt_int, 1
print newline
print fmt_str, str_9
mov rbx, 0
add rbx, 1
print fmt_int, rbx
print newline
print fmt_str, str_10
mov rcx, 3
sub rcx, 1
print fmt_int, rcx
print newline
mov s, 0
add s, 1
print fmt_str, str_11
print fmt_int, s
print fmt_str, str_12
print newline
add s, 2
print fmt_str, str_13
print fmt_int, s
print fmt_str, str_14
print newline
sub s, 1
print fmt_str, str_15
print fmt_int, s
print fmt_str, str_16
print newline
print fmt_str, str_17
push rbx
push rcx
mov rbx, 0
call FUNC_DirectionDegrees
pop rcx
pop rbx
mov rdx, rax
print fmt_int, rdx
print fmt_str, str_18
push rbx
push rcx
push rdx
mov rbx, 1
call FUNC_DirectionDegrees
pop rdx
pop rcx
pop rbx
mov rsi, rax
print fmt_int, rsi
print fmt_str, str_19
push rbx
push rcx
push rdx
push rsi
mov rbx, 2
call FUNC_DirectionDegrees
pop rsi
pop rdx
pop rcx
pop rbx
mov rdi, rax
print fmt_int, rdi
print fmt_str, str_20
push rbx
push rcx
push rdx
push rsi
push rdi
mov rbx, 3
call FUNC_DirectionDegrees
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r8, rax
print fmt_int, r8
print newline
print newline
print fmt_str, str_21
print newline
print fmt_str, str_22
print newline
mov s, 0
FOR_3:
cmp s, 3
jg ENDFOR_4
cmp s, 0
je IN_FOUND_8
cmp s, 1
je IN_FOUND_8
mov r9, 0
jmp IN_END_9
IN_FOUND_8:
mov r9, 1
IN_END_9:
cmp r9, 0
je ELSE_6
print fmt_str, str_23
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov rbx, s
call FUNC_SeasonName
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov _tmpptr0, arg0
print fmt_str, _tmpptr0
print fmt_str, str_24
print newline
jmp ENDIF_7
ELSE_6:
print fmt_str, str_23
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov rbx, s
call FUNC_SeasonName
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov _tmpptr0, arg0
print fmt_str, _tmpptr0
print fmt_str, str_25
print newline
ENDIF_7:
FOR_CONTINUE_5:
add s, 1
jmp FOR_3
ENDFOR_4:
print fmt_str, str_26
print newline
mov n, 1
FOR_10:
cmp n, 20
jg ENDFOR_11
cmp n, 2
je IN_FOUND_15
cmp n, 3
je IN_FOUND_15
cmp n, 5
je IN_FOUND_15
cmp n, 7
je IN_FOUND_15
cmp n, 11
je IN_FOUND_15
cmp n, 13
je IN_FOUND_15
cmp n, 17
je IN_FOUND_15
cmp n, 19
je IN_FOUND_15
mov r9, 0
jmp IN_END_16
IN_FOUND_15:
mov r9, 1
IN_END_16:
cmp r9, 0
je ELSE_13
print fmt_int, n
print fmt_str, str_27
jmp ENDIF_14
ELSE_13:
print fmt_int, n
print fmt_str, str_28
ENDIF_14:
FOR_CONTINUE_12:
add n, 1
jmp FOR_10
ENDFOR_11:
print newline
print newline
print fmt_str, str_29
print newline
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov arg0, shape1
mov rbx, 10
mov rcx, 20
mov arg1, str_30
call PROC_InitShape
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
store 0, shape1, 24, 1
store 5, shape1, 32, 1
load _tmpptr0, shape1, 0, 1
print fmt_str, _tmpptr0
print fmt_str, str_31
load r9, shape1, 8, 1
print fmt_int, r9
print fmt_str, str_32
load r9, shape1, 16, 1
print fmt_int, r9
print fmt_str, str_33
load r9, shape1, 32, 1
print fmt_int, r9
print fmt_str, str_34
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov arg0, shape1
call FUNC_ShapeArea
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r9, rax
print fmt_int, r9
print newline
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov arg0, shape2
mov rbx, 30
mov rcx, 40
mov arg1, str_35
call PROC_InitShape
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
store 1, shape2, 24, 1
store 8, shape2, 32, 1
store 6, shape2, 40, 1
load _tmpptr0, shape2, 0, 1
print fmt_str, _tmpptr0
print fmt_str, str_31
load r9, shape2, 8, 1
print fmt_int, r9
print fmt_str, str_32
load r9, shape2, 16, 1
print fmt_int, r9
print fmt_str, str_36
load r9, shape2, 32, 1
print fmt_int, r9
print fmt_str, str_37
load r9, shape2, 40, 1
print fmt_int, r9
print fmt_str, str_38
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov arg0, shape2
call FUNC_ShapeArea
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r9, rax
print fmt_int, r9
print newline
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov arg0, shape3
mov rbx, 50
mov rcx, 60
mov arg1, str_39
call PROC_InitShape
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
store 2, shape3, 24, 1
store 10, shape3, 32, 1
store 7, shape3, 40, 1
store 8, shape3, 48, 1
load _tmpptr0, shape3, 0, 1
print fmt_str, _tmpptr0
print fmt_str, str_31
load r9, shape3, 8, 1
print fmt_int, r9
print fmt_str, str_32
load r9, shape3, 16, 1
print fmt_int, r9
print fmt_str, str_40
load r9, shape3, 32, 1
print fmt_int, r9
print fmt_str, str_34
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov arg0, shape3
call FUNC_ShapeArea
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r9, rax
print fmt_int, r9
print newline
print newline
print fmt_str, str_41
print newline
store 101, emp1, 0, 1
store str_42, emp1, 8, 1
store 0, emp1, 16, 1
store 25, emp1, 24, 1
store 160, emp1, 32, 1
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov arg0, emp1
call PROC_PrintEmployee
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
store 102, emp2, 0, 1
store str_43, emp2, 8, 1
store 1, emp2, 16, 1
store 75000, emp2, 24, 1
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov arg0, emp2
call PROC_PrintEmployee
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
print newline
print fmt_str, str_44
print newline
print fmt_str, str_45
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov rbx, 42
mov rcx, 17
call FUNC_Max
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r9, rax
print fmt_int, r9
print newline
print fmt_str, str_46
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov rbx, 3
mov rcx, 99
call FUNC_Max
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r9, rax
print fmt_int, r9
print newline
print fmt_str, str_47
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov rbx, 150
mov rcx, 0
mov rdx, 100
call FUNC_Clamp
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r9, rax
print fmt_int, r9
print newline
print fmt_str, str_48
mov r9, 0
sub r9, 5
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov rbx, r9
mov rcx, 0
mov rdx, 100
call FUNC_Clamp
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r10, rax
print fmt_int, r10
print newline
print fmt_str, str_49
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
mov rbx, 50
mov rcx, 0
mov rdx, 100
call FUNC_Clamp
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r9, rax
print fmt_int, r9
print newline
print newline
print fmt_str, str_50
print newline
mov count, 0
GOTO_100_17:
mov r9, count
add r9, 1
mov count, r9
cmp count, 5
jle ELSE_18
jmp GOTO_200_22
ELSE_18:
print fmt_int, count
print fmt_str, str_51
jmp GOTO_100_17
GOTO_200_22:
print newline
print fmt_str, str_52
print newline
print newline
print fmt_str, str_53
print newline
free shape1
free shape2
free shape3
free emp1
free emp2
done
function PROC_InitShape:
mov InitShape_s, arg0
mov InitShape_nx, rbx
mov InitShape_ny, rcx
mov InitShape_shapeName, arg1
store InitShape_shapeName, InitShape_s, 0, 1
store InitShape_nx, InitShape_s, 8, 1
store InitShape_ny, InitShape_s, 16, 1
PROC_END_InitShape:
ret
function PROC_PrintEmployee:
mov PrintEmployee_e, arg0
print fmt_str, str_54
load rbx, PrintEmployee_e, 0, 1
print fmt_int, rbx
print fmt_str, str_55
load _tmpptr0, PrintEmployee_e, 8, 1
print fmt_str, _tmpptr0
print newline
load rcx, PrintEmployee_e, 16, 1
cmp rcx, 0
jne ELSE_23
print fmt_str, str_56
load rsi, PrintEmployee_e, 24, 1
print fmt_int, rsi
print fmt_str, str_57
load rdi, PrintEmployee_e, 32, 1
print fmt_int, rdi
print fmt_str, str_58
load r8, PrintEmployee_e, 24, 1
load r9, PrintEmployee_e, 32, 1
mov r10, r8
mul r10, r9
print fmt_int, r10
print newline
jmp ENDIF_24
ELSE_23:
print fmt_str, str_59
load r9, PrintEmployee_e, 24, 1
print fmt_int, r9
print fmt_str, str_60
print newline
ENDIF_24:
PROC_END_PrintEmployee:
ret
function FUNC_SeasonName:
mov SeasonName_s, rbx
cmp SeasonName_s, 0
je CASE_0_28
cmp SeasonName_s, 1
je CASE_1_29
cmp SeasonName_s, 2
je CASE_2_30
cmp SeasonName_s, 3
je CASE_3_31
jmp CASE_ELSE_32
CASE_0_28:
mov __funcret_SeasonName, str_61
jmp CASE_END_27
CASE_1_29:
mov __funcret_SeasonName, str_62
jmp CASE_END_27
CASE_2_30:
mov __funcret_SeasonName, str_63
jmp CASE_END_27
CASE_3_31:
mov __funcret_SeasonName, str_64
jmp CASE_END_27
CASE_ELSE_32:
mov __funcret_SeasonName, str_65
CASE_END_27:
FUNC_END_SeasonName:
mov arg0, __funcret_SeasonName
ret
function FUNC_DirectionDegrees:
mov DirectionDegrees_d, rbx
mul rbx, 90
mov __funcret_DirectionDegrees, rbx
FUNC_END_DirectionDegrees:
mov rax, __funcret_DirectionDegrees
ret
function FUNC_ShapeArea:
mov ShapeArea_s, arg0
load rbx, ShapeArea_s, 24, 1
cmp rbx, 0
je CASE_0_34
cmp rbx, 1
je CASE_1_35
cmp rbx, 2
je CASE_2_36
jmp CASE_ELSE_37
CASE_0_34:
load rcx, ShapeArea_s, 32, 1
mov rdx, 3
mul rdx, rcx
load rsi, ShapeArea_s, 32, 1
mov __funcret_ShapeArea, rdx
mul __funcret_ShapeArea, rsi
jmp CASE_END_33
CASE_1_35:
load r8, ShapeArea_s, 32, 1
load r9, ShapeArea_s, 40, 1
mov r10, r8
mul r10, r9
mov __funcret_ShapeArea, r10
jmp CASE_END_33
CASE_2_36:
load r9, ShapeArea_s, 32, 1
load r10, ShapeArea_s, 40, 1
mul r9, r10
div r9, 2
mov __funcret_ShapeArea, r9
jmp CASE_END_33
CASE_ELSE_37:
mov __funcret_ShapeArea, 0
CASE_END_33:
FUNC_END_ShapeArea:
mov rax, __funcret_ShapeArea
ret
function FUNC_Max:
mov Max_a, rbx
mov Max_b, rcx
cmp Max_a, Max_b
jle ELSE_38
mov __funcret_Max, Max_a
jmp ENDIF_39
ELSE_38:
mov __funcret_Max, Max_b
ENDIF_39:
FUNC_END_Max:
mov rax, __funcret_Max
ret
function FUNC_Clamp:
mov Clamp_val, rbx
mov Clamp_lo, rcx
mov Clamp_hi, rdx
mov __funcret_Clamp, Clamp_val
cmp __funcret_Clamp, Clamp_lo
jge ELSE_42
mov __funcret_Clamp, Clamp_lo
ELSE_42:
cmp __funcret_Clamp, Clamp_hi
jle ELSE_46
mov __funcret_Clamp, Clamp_hi
ELSE_46:
FUNC_END_Clamp:
mov rax, __funcret_Clamp
ret
}
}