-
Notifications
You must be signed in to change notification settings - Fork 6
/
vmal_ex.vmal
65 lines (48 loc) · 2.63 KB
/
vmal_ex.vmal
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
# This is a comment
# Apart from comments, every line should end with a ;
4: 1024; # This is also a comment, after a register initializer
# You may also indent however you want
# This register initializer sets the value of register
# 4 (which is the TIR register) to the value 1024
A: 0x1D; # This initializes the value of register A (which is
# also called the A register) to the value 1D in
# hexadecimal, which is equal to 29
D: 0b00110001; # This initializes the value of register D (which
# is also called the D register) to the value
# 110001 in binary, which is 49
[1024]: 34; # This initializes the value of memory location 1034
# to the value 34
[0x401]: 0b101; # This initializes the value of memory location
# 0x404 (which is memory location 1025) to the
# value 101 in binary, which is 5
[0b10000000010]: 0x10; # This initializes the value of memory
# location 0b10000000010 (which is memory
# location 1026) to the value 10 in
# hexadecimal, which is 16
ADD E, A; # This adds the value of register A to register E, and
# stores the result in E
AdD e, A; # Same as above, but VMAL is case insensitive (with the
# exception of labels)
LBL JumpHere; # Creates a label at this position. This does not
# end up in the final assembled code
ADD E, 7; # Adds -1 to E (note that 7 is the address of the -1
# register, which is initially set to -1)
SF E; # Sets the N and Z flags depending on the value in E
BIZ JumpHere; # Branches to JumpHere if the Z flag is true (if
# E was 0 when the above SF instruction was run)
GO JumpHERE; # Branches to the JumpHERE label BELOW, since
# labels are case sensitive
LBL JumpHERE;
LBL JumpHere_236; # Extra labels don't matter
# LBL JumpHere; # According to the way that VMAL is implemented,
# the last definition for a certain label is the
# only valid label, so if this line was not
# commented, the BIZ JumpHere operation would
# branch to this instead of the first label.
SA 4; # Sets the value of the MAR to the value of register 4
# (which is the TIR register)
RD; # Performs a read from main memory
RB 3; # Sets the value of register 3 (which is the IR register)
# to the value of the MBR
# At this point, IR should hold the value of 34, as the
# main memory at location 1024 was initialized with 34