-
Notifications
You must be signed in to change notification settings - Fork 0
/
sized_math.al
110 lines (88 loc) · 1.5 KB
/
sized_math.al
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
main :: proc () {
puts("assigns\n")
big := 228282982198
var a s32
var dword u32
var word u16
var byte u8
var byte_signed s8
var full s64
// sign extension and zero extension
a = -1
byte = 255
a = byte
print_int(a)
a = -1
word = 65535
a = word
print_int(a)
full = -1
dword = 4294967295
full = dword
print_int(full)
a = -1
byte_signed = -123
a = byte_signed
print_int(a)
puts("\naddition\n")
a = 626
print_int(a)
a += big
print_int(a)
byte = 232
byte += big
print_int(byte)
b := big
a = -382
b = b + a
print_int(b)
byte_signed = -122
b = big
b += byte_signed
print_int(b)
puts("\nsubtration:\n")
a = 626
a -= big
print_int(a)
byte = 232
byte -= big
print_int(byte)
b = big
a = -382
b = b - a
print_int(b)
byte_signed = -122
b = big
b -= byte_signed
print_int(b)
puts("\nmultiplication:\n")
full = 251
a = -1234125
full = full * a
print_int(full)
a = 251
byte = 143
a = a * byte
print_int(a)
a = 251
byte_signed = -112
a = a * byte_signed
print_int(a)
byte = 82
byte = byte * big
// the result is funny because after the multiply there is
// junk in the upper half of the register. It will be fixed when we type check function call arguments
print_int(byte)
puts("\ndivision:\n")
byte = 29
b = 3
byte = byte / b
print_int(byte)
a = 281924
// 96 * 4 = 384 which is -128 in s8 with one extra bit. Testing sign extenion.
byte_signed = 96
byte_signed = byte_signed * 4
print_int(byte_signed)
a = a / byte_signed
print_int(a)
}