0

I'm trying to count the number of characters in LC3 simulator and keep getting "a trap was executed with an illegal vector number". These are the objects I execute

charcount.obj:

0011000000000000

0101010010100000 0010011000010000 1111000000100011 0110001011000000 0001100001111100 0000010000001000 1001001001111111 0001001001100001 0001001001000000 0000101000000001 0001010010100001 0001011011100001 0110001011000000 0000111111110110 0010000000000100 0001000000000010 1111000000100001 1111000000100101 1110001011111111 0000000000110000

and verse: .ORIG x3100

.STRINGZ "Simple Simon met a pieman,"
.STRINGZ "Going to the fair;"
.STRINGZ "Says Simple Simon to the pieman,"
.STRINGZ "Let me taste your ware."

.FILL   x04

.END

1 Answer 1

0

Looks like we're going to need more information before we can help you much. I understand you've provided us with some binary and I ran that through the LC3 simulator. Here's where I'm a bit lost, which string would you like to count and where is it stored?

After trying to piece together what you've provided here's what I've found.

Registers:

R0   x0061  97
R1   x0000  0
R2   x0000  0
R3   xE2FF  -7425
R4   x0000  0
R5   x0000  0
R6   x0000  0
R7   x3003  12291
PC   x3004  12292
IR   x62C0  25280
CC   Z

Memory:

x3000  0101010010100000  x54A0            AND    R2, R2, #0     
x3001  0010011000010000  x2610            LD     R3, x3012      
x3002  1111000000100011  xF023            TRAP   IN             
x3003  0110001011000000  x62C0            LDR    R1, R3, #0     
x3004  0001100001111100  x187C            ADD    R4, R1, #-4    
x3005  0000010000001000  x0408            BRZ    x300E          
x3006  1001001001111111  x927F            NOT    R1, R1         
x3007  0001001001100001  x1261            ADD    R1, R1, #1     
x3008  0001001001000000  x1240            ADD    R1, R1, R0     
x3009  0000101000000001  x0A01            BRNP   x300B          
x300A  0001010010100001  x14A1            ADD    R2, R2, #1     
x300B  0001011011100001  x16E1            ADD    R3, R3, #1     
x300C  0110001011000000  x62C0            LDR    R1, R3, #0     
x300D  0000111111110110  x0FF6            BRNZP  x3004          
x300E  0010000000000100  x2004            LD     R0, x3013      
x300F  0001000000000010  x1002            ADD    R0, R0, R2     
x3010  1111000000100001  xF021            TRAP   OUT            
x3011  1111000000100101  xF025            TRAP   HALT           
x3012  1110001011111111  xE2FF            LEA    R1, x3112      
x3013  0000000000110000  x0030            NOP                   

The values displayed in the registers is what I get when I stop after line x3003. For some reason the literal value of xE2FF gets loaded into register R3. After that the value of 0 at memory location xE2FF is loaded into register R1 and then the problems mount from there.

I would recommend displaying your asm code and then commenting each line so we can better understand what you're trying to accomplish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.