Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: The return pointer in TRAP is still saved using R7 #17

Open
yezhiyi9670 opened this issue Dec 15, 2023 · 1 comment
Open

Bug: The return pointer in TRAP is still saved using R7 #17

yezhiyi9670 opened this issue Dec 15, 2023 · 1 comment

Comments

@yezhiyi9670
Copy link

yezhiyi9670 commented Dec 15, 2023

TRAP routines seem to modify R7 to the incremented PC, causing R7 to be changed unexpectedly.

.ORIG x3000

            LEA R0, STR1
            AND R7, R7, #0
            ADD R7, R7, #3
            PUTS            ; Call PUTS
            LD R0, CHR48
            ADD R0, R0, R7  ; Convert R7 to character
            OUT             ; Output R7 as digit

            HALT

STR1        .STRINGZ "Message\n"
CHR48       .FILL x30

.END
@yezhiyi9670
Copy link
Author

yezhiyi9670 commented Dec 15, 2023

In this version of LC-3 handbook, PC is saved using R7. However, according to the appendix of the latest textbook, the incremented PC is directly pushed onto the system stack. TRAP should do this instead:

TEMP = PSR;
if (PSR[15] == 1)
   Saved_USP = R6 and R6 = Saved_SSP
   PSR[15] = 0
Push TEMP.PC on the system stack
PC = mem[ZEXT(trapvect8)];

@yezhiyi9670 yezhiyi9670 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2023
@yezhiyi9670 yezhiyi9670 changed the title Bug: PUTS routine does not save R7 properly Bug: The return pointer in TRAP is still saved using R7 Dec 19, 2023
@yezhiyi9670 yezhiyi9670 reopened this Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant