; Example 2 -- Count the number of character occurrences in a file ; This file contains the instructions (in binary format) ; The file containing the data is ex2_data.asm ; load operating system lc3os.obj first .ORIG x3000 ; Start program at x3000 .FILL b0101010010100000 ; R2 <- 0 (counter) .FILL b0010011000010000 ; R3 <- M[x3012] (ptr) .FILL b1111000000100011 ; Input to R0 (TRAP x23) .FILL b0110001011000000 ; R1 <- M[R3] .FILL b0001100001111100 ; R4 <- R1 - 4 (EOT) .FILL b0000010000001000 ; If Z, goto x300E .FILL b1001001001111111 ; R1 <- NOT R1 .FILL b0001001001100001 ; R1 <- R1 + 1 .FILL b0001001001000000 ; R1 <- R1 + R0 .FILL b0000101000000001 ; if N or P, goto x300B .FILL b0001010010100001 ; R2 <- R2 + 1 .FILL b0001011011100001 ; R3 <- R3 + 1 .FILL b0110001011000000 ; R1 <- M[R3] .FILL b0000111111110110 ; Goto x3004 .FILL b0010000000000100 ; R0 <- M[x3013] .FILL b0001000000000010 ; R0 <- R0 + R2 .FILL b1111000000100001 ; Print R0 (TRAP x21) .FILL b1111000000100101 ; HALT (TRAP x25) .FILL b0011000100000000 ; File starts at x3100 .FILL b0000000000110000 ; ASCII x30 ('0')