Hello there everyone!
I'm just beginning to dabble along with 68k assembler. I've been doing it on and off since friday and I've come up with a simple sumpink for emulating the CPU of the PDP-8. Loads of things are still missing, but first of all I want to get the routine for indirect adressing working properly.
So, here's my source. first comes the pdp-8 code, explained below, and then the "emulator" starts at org $1000.
A0 I've designated to the emulated machine's program counter.
A1 holds the adress to the operand which the emulated machine current working on.
D0 holds the opcode which is being executed.
D1 is the accumulator of the emulated machine.
Anyway, here comes the pdp-8 code I'm trying to run, with addresses and machine code in octal
and here is the "emulator"Code:0000 1007 tad 0007 ;add to AC whatever's in location 7 0001 3406 dca i 0006 ;deposit AC to the location pointed to by 0006, and clear AC. 0002 2006 isz 0006 ;increment location 0006 by one, and skip next instruction if 0 0003 5000 jmp 0000 ;jump to location 0000 0004 7402 hlt ;halt processor. 0005 0006 0010 0007 5252 0010 ; first location to be written to
the first few pdp-8 instruction run just fine. but then something goes tits up in the routine that deals with indirect adressing, which has unwanted consequences on the rest of the program, because the third instruction then doesn't work.Code:* pppp d pppp 888 / ee mm mm * p p d p p 8 8 / e e m m m * pppp dddd pppp 888 / eee m m m * p d d p 8 8 / e m m m * p dddd p 888 / eee m m m * * by s a m. f r. j u l. 2 0. 2 0 0 7. * version zero. attempts to run pdp-8 code. memloc0 dc.w $0207 * tad 0007 memloc1 dc.w $0706 * dca i 0006 memloc2 dc.w $0406 * isz 0006 memloc3 dc.w $0a00 * jmp 0000 memloc4 dc.w $0F02 * hlt memloc5 dc.w $0000 memloc6 dc.w $0008 * starting adress memloc7 dc.w $0aaa * fill pattern START org $1000 OPFETCH move.w (a0)+,d0 put current opcode into d0. move d0,d2 time to calculate what adress is being reffed to andi.w #$FF,d2 asl #$1,d2 make sure we've got an even adress. bclr #$8,d2 zero page? beq DIRECTION yup. that's what we have now, so see if we want indirection. move a0,d3 otherwise, get page from upper 5 bits of PC. ori.w #$FF80,d3 or.w d3,d2 DIRECTION btst #$9,d0 now, are we dealing with indirect adressing? beq INDIRECT yes, so do it. move d2,a1 otherwise, put address into appropriate register jmp OPPARSE and see what's next to go down inda hood. INDIRECT move.w d2,a2 move.w (a2),a1 use a2 as scratchpad for loading effective adress into adress register OPPARSE asr #$8,d0 get rid of everything but the command. asr #$1,d0 we have everything we need. cmpi #$0,d0 beq ANDOP cmpi #$1,d0 beq TADOP cmpi #$2,d0 beq ISZOP cmpi #$3,d0 beq DCAOP cmpi #$4,d0 beq JMSOP cmpi #$5,d0 beq JMPOP cmpi #$6,d0 beq IOTOP cmpi #$7,d0 beq OPROP ANDOP move (a1),d2 AND - self explanatory and d2,d1 jmp INTER TADOP add (a1),d1 TAD - add operand to accumulator jmp INTER ISZOP move.w (a1),d2 ISZ - increment operand by 1. Skip next instruction if it overflows to 0 addq.w #$1,d2 andi.w #$0fff,d2 bne NOSKIP addq #$2,a0 NOSKIP andi.w #$f000,(a1) rightmost twelve bits will always be 0 in this case or.w d2,(a1) jmp INTER DCAOP move.w d1,(a1) DCA - deposit and clear accumulator move.w #$0,d1 jmp INTER JMSOP move a0,(a1)+ JMS - store PC at word move a1,a0 and continue execution from the following word addq #$2,a0 execute next command after that. jmp OPFETCH in this case, don't allow an interrupt to be dealt with till next round JMPOP move.w a1,a0 JMP - jump jmp INTER IOTOP addq #$2,a0 jmp INTER IOT - input output transfers. fill this in later OPROP addq #$2,a0 OPR - microcoded operations. fill this in later. jmp INTER INTER nop deal with interrupts. fill this in later jmp opfetch MOVE.B #9,D0 TRAP #15 Halt Simulator END START
Can anyone here tell what's up with my code?



Reply With Quote

