repos / lc3vm.zig.git


lc3vm.zig.git / src
Evgenii Akentev  ·  2025-11-01

main.zig

 1const std = @import("std");
 2const lc3vm_zig = @import("lc3-vm_zig");
 3
 4pub fn main() !void {
 5    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); 
 6    defer arena.deinit();
 7
 8    var memory = &lc3vm_zig.memory;
 9
10    memory[0x3000] = 0xF026;    //  1111 0000 0010 0110             TRAP trp_in_u16  ;read an uint16_t from stdin and put it in R0
11    memory[0x3002] = 0x1220;    //  0001 0010 0010 0000             ADD R1,R0,x0     ;add contents of R0 to R1
12    memory[0x3003] = 0xF026;    //  1111 0000 0010 0110             TRAP trp_in_u16  ;read an uint16_t from stdin and put it in R0
13    memory[0x3004] = 0x1240;    //  0001 0010 0010 0000             ADD R1,R1,R0     ;add contents of R0 to R1
14    memory[0x3006] = 0x1060;    //  0001 0000 0110 0000             ADD R0,R1,x0     ;add contents of R1 to R0
15    memory[0x3007] = 0xF027;    //  1111 0000 0010 0111             TRAP trp_out_u16;show the contents of R0 to stdout
16    memory[0x3008] = 0xF025;    //  1111 0000 0010 0101             HALT             ;halt
17
18    try lc3vm_zig.start(arena.allocator(), 0);
19}
20