- Notice the difference between # and $ → Hash starts with H therefore it means HEX → Dollar starts with D therefore it means DECIMAL
Subroutines
A Subroutine is: - Some instructions to do a task - could be called from several places
BL (Branch with link) - What does BL do? → LR gets the PC → PC gets PC + decoded offset
Ex: BL Subroutine ---------- >> goes to Subroutine Subroutine executes.... We don't have/need a return statement. We do not have an instruction to actually do a return. We can do it with MOV LR, PC ←← PC gets LR We can also use the SWAP instruction (exchanges two registers) and do SWAP LR PC ←← Temp register gets PC, PC gets LR, LR gets temp. The temp register (T) is not user accessible.
Larry wrote a little program :3
Hopefully he posts this bc I'm not gonna be able to copy it all down sry james >> update: it is posted It's called SUBR1.asm
org #1000 Test movls #FF,R0 bl Subr
When he ran this through the assembler it did two passes. Why? Because Subr is a forward reference.
Larry keeps saying that some people were doing their loader “by hand” aka loading each byte 1 by 1 ? Idk what's wrong with that or what to do instead. When he does his memory dump he also shows the ascii equivalent after the hex bytes he recommends displaying the memory in lines of 16 How do you do the ascii thing? You print them as chars, but you have to make sure it's a printable character. If not, print a . Breakpoint: Within your execution loop: WHILE Run_CPU DO f() d() e() Run_CPU ← (PC != breakpoint) END Larry put a breakpoint at 1004. Why? because that should be the “next instruction” after the subroutine returns. It didn't work so he's going through the list file to figure out what went wrong. He's going to put a breakpoint at 2000 since that is within the subroutine to see if that's what's going wrong. It stops at 2000. He does a register dump R0 is FFFF LR is 1004 PC is 2000 he did a single step. PC is now 2002 R0 is now 0000 (becuase of carry) One more step and the subroutine should return. The pc should be 1004 But it is 2004. This means that the subroutine does not return. Something has gone wrong with the mov instruction (mov LR, PC) The instruction says FF80 (the first 3 bits are definitely wrong) This means the loader is working, the machine seems to be wrong, the assembler is wrong. Long story short he had an unsigned short that should have been signed, since a function related to that variable returned -1 if the operation failed. Since they wre unsigned, the -1 would not flag as a failure The problem is LR and PC are not in the symbol table of the assembler and larry thought they were. He changed the values in the old assembler to R5 R7 (or something I forget, but the values of LR and PC) Now it works in the old assembler. Now setting a breakpoint at 1004 works. The new assembler fixed this issue. The new assembler releases a diagnostic if the symbols are not defined.
Control C Software
Control C should terminate whatever is running. He wrote some software that should catch when CTRL C is thrown. While CPU_GO{ fetch() decode() execute() CPU_GO = !ctrl_c_find && PC != brkpt && !single_step }
Someone typing control C is considered an exception. C allows us to specify an exception handler. There is a table for SIGINT(signal interrupt) and a function to handle it. The way we specify a function is in the debuggger's startup code. We call signal(SIGINT, (_crt_signal_t)sigint_hdlr) We have to reinitialize this every time we want to catch another ctrl C #incude <signal.h>
How would we write a = b + c in the XM23 assembler. Say b = R3 and c = R2 What happens if we do ADD R3, R2? R2 ← R3 + R2 b = 10 c = 3 How do we assign an immediate to a register? MOVLZ $10 R3 MOVLZ $3, R2 Then: ADD R3, R2 ; now R2 is our value for ‘a’
Larry starts writing a new asm file:
; ; Sample addition a = b + c ;
org #100 Mainline movlz $10,R3 movlz $3,R2 ; ; a = b + c add R3,R2 ; Done end Mainline
Assembler produces: the movlz is 6853 0110 1000 0101 0011 01101(opcode) 00001010 (0A) $10 011 (R3)
We can also look at the xme file that the assembler produced The S1 record: S1[09][0100][53681A681A40][5E] If we set a breakpoint at 106 (location of Done) and check out the registers, R2 = 000D and R3 = 000A R2 is 13 because it was the destination of the addition R3 is still 10 because it did not change.