Results 1 to 8 of 8

Thread: Assembly

  1. #1
    Harmless Inactive Member
    wilsonsamm's Avatar
    Join Date
    May 2007
    Posts
    17
    Downloads
    0
    Uploads
    0

    Assembly

    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
    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
    and here is the "emulator"
    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
    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.

    Can anyone here tell what's up with my code?

  2. #2
    Retro Addict Administrator
    My location

    Burger Time Champion, Sonic Champion Harrison's Avatar
    Join Date
    Dec 2002
    Location
    UK
    Posts
    16,662
    Blog Entries
    1
    Downloads
    6
    Uploads
    14
    Sorry, I never bothered learning assembler, instead sticking to higher level languages. Hopefully others here might be able to help. Submeg?

    If you haven't played a classic game in years, it's never too late to start!


  3. #3
    ELITE Staff Moderator
    My location

    Snake Champion, Invasion Champion Puni/Void's Avatar
    Join Date
    May 2003
    Location
    Norway
    Posts
    2,055
    Blog Entries
    5
    Downloads
    0
    Uploads
    1
    Sadly I can't help you with your queries either, but hopefully someone else can be of assistance. Cool to see that you are learning Assembler by the way! Good luck with the source!

  4. #4
    Harmless Inactive Member
    wilsonsamm's Avatar
    Join Date
    May 2007
    Posts
    17
    Downloads
    0
    Uploads
    0
    Thanks! It's cool to be learning it! It's always good to learn something new.
    Maybe there's another 68k board somewhere on the net someone could suggest to me?

  5. #5
    Wiseguy Staff Moderator
    My location

    Teho's Avatar
    Join Date
    Dec 2002
    Location
    Norway
    Posts
    1,322
    Downloads
    1
    Uploads
    0
    You should definitely try one of the demoscene boards like the one on scene.org then. If anyone knows 68k assembler, it's them.

  6. #6
    ELITE Staff Member
    My location

    Space Invaders Champion, Flash Sprint Champion, Seconds Of Madness Champion, BMX Park Champion Submeg's Avatar
    Join Date
    Jul 2004
    Location
    Adelaide, SA
    Posts
    2,666
    Blog Entries
    3
    Downloads
    0
    Uploads
    0
    Yea I will have a look later, but I havent done it in a while so it may take a little while
    Check out my blog - submeg.com/

  7. #7
    Harmless Inactive Member
    wilsonsamm's Avatar
    Join Date
    May 2007
    Posts
    17
    Downloads
    0
    Uploads
    0
    I sussed it
    When the adress is direct, there's a command which says "asl.w #$1,d2". this basically doubles the adress, so that this number is the adress in bytes, like the 68k does it, not words as does the PDP-8. This of course, has to be done again if it's indirect adressing aswell.
    I'm well chuffed

  8. #8
    ELITE Staff Member
    My location

    Space Invaders Champion, Flash Sprint Champion, Seconds Of Madness Champion, BMX Park Champion Submeg's Avatar
    Join Date
    Jul 2004
    Location
    Adelaide, SA
    Posts
    2,666
    Blog Entries
    3
    Downloads
    0
    Uploads
    0
    nice work man...I was like lol
    Check out my blog - submeg.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright classicamiga.com