Results 1 to 9 of 9

Thread: For Loops, While Loops, and If statements

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    For Loops, While Loops, and If statements

    Howdy.

    I'm learning Assembly for the M68000, and its coming along nicely. But I just cant get my head around trying to translate java for/while loops and if statements into assembly. Ive seen lots of examples.... but I just cant follow whats going on.

    Does anyone have a couple of examples, or perhaps just a short tutorial on the matter ?

    Thanks,
    Jamie.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  2. #2
    scoutt
    Guest
    are you working on the 68hc11?

    can you post the code you want transfered?

  3. #3

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Its for the M68000... thats all I know.

    Anyway I was working on it last night and had a sort of epiphany about how to do branch instructions. Are the pieces of code below correct ? I think they are, but I'm not 100% sure on it.


    Code:
    * 
    * int x, y, low, high;
    * 
    * if (x >= y) 
    * 	low = y;
    * 	high = x;
    * else
    * 	low = x;
    * 	high = y;
    * 
    
    	ORG $1000
    
    X	DC.L	$20
    Y	DC.L	$10
    LOW	DC.L	$0
    HIGH	DC.L	$0
    
    	MOVE.L	X,D0
    	MOVE.L	Y,D1
    	MOVE.L	LOW,D2
    	MOVE.L	HIGH,D3
    
    	CMP	D0,D1
    	BPL	IFTRUE
    	
    IFELSE	MOVE.L	D0,LOW
    	MOVE.L	D1,HIGH
    	BRA	NEXT
    
    IFTRUE	MOVE.L	D1,LOW
    	MOVE.L	D0,HIGH
    
    NEXT	STOP	#$2700
    	END	$1000
    Code:
    * 
    * loop {
    * 	x = x + 1;
    * 	if (x > y) break;
    * 	y = y - 2;
    * }
    * 
    
    	ORG	$1000
    X	DC.L	$100
    Y	DC.L	$200
    
    	MOVE.L	X,D0
    	MOVE.L	Y,D1
    
    LOOP	ADDI.L	#$1,D0
    	CMP.L	D0,D1
    	BLE	BREAK
    	SUBI.L	#$2,D1
    	BRA LOOP
    
    BREAK	STOP	#$2700
    	END 	$1000
    Code:
    * 
    * Write a 68K Assembler program for the following task: A byte at address $4000
    * contains an unsigned item count value, which indicates how many of the
    * subsequent words are valid unsigned data. The valid words are to be multiplied
    * together to give an unsigned longword result, to be stored at address $2000.
    * 
    
    FIRST	EQU	$4000
    DESTLOC	EQU	$2000
    
    
    	ORG	$1000
    
    	MOVE.L	#$3000,D0
    	MOVE.L	#FIRST,A0
    	MOVE.L	#$1,D2
    
    LOOP	ADDI.B	#$1,(A0)
    	MULU	(A0),D2
    	SUBI.B	#$1,D0
    	BNE	LOOP
    
    	MOVE.L	D2,$2000
    	STOP	#$2700
    	END $1000
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    scoutt
    Guest
    I think all code for the M68000 is al the same. I worked on this and it was for the 68hc11 which was the type of chip we downloaded to.

    I looked it over and it looks ok to me. I wasn't sure what the MOVE.L was so I had to look it up.

    I do have one question though, on this code
    Code:
    * 
    * Write a 68K Assembler program for the following task: A byte at address $4000
    * contains an unsigned item count value, which indicates how many of the
    * subsequent words are valid unsigned data. The valid words are to be multiplied
    * together to give an unsigned longword result, to be stored at address $2000.
    * 
    
    FIRST	EQU	$4000
    DESTLOC	EQU	$2000
    
    
    	ORG	$1000
    
    	MOVE.L	#$3000,D0
    	MOVE.L	#FIRST,A0
    	MOVE.L	#$1,D2
    
    LOOP	ADDI.B	#$1,(A0)
    	MULU	(A0),D2
    	SUBI.B	#$1,D0
    	BNE	LOOP
    
    	MOVE.L	D2,$2000
    	STOP	#$2700
    	END $1000
    did you take the number that was at address 4000? it looks like you took whatever was in 3000 and moved it to the first byte in 4000, I could be wrong since it has been a year since I worked on this. If the valid words are to be multiplied then why did you subtract and add them? or are you just subtracting the from teh main one to get to 0.

    other than that you used the branches right, good job. let me know the outcome if this was a test.

  5. #5

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Hmmm yeah I shouldnt have moved the #$value into the A0 register, but just the $value to reference an address..

    And the $3000 business. I did that last night and I cant remember why. I think it was just to have a counter, and I'm subtracting 1 from it each iteration so that we can do just 3000...

    So therefore I'm not answering the question...
    I think actually maybe I did that as though I was assuming the number stored at address $4000 was #$3000.
    So we should do 3000 repititions. Ahh I dunno

    Anyway yeah its a test tomorrow.
    There's lots more on the paper, about binary representations, 2s complement, 1s complement, addition, subtraction and then assembly.
    Normally we have to convert java fragments into assembly.
    I quite like it.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    scoutt
    Guest
    oh you answered the question. I was mistaken on that #$3000, I was thinking it was an address instead of a number. anyway yeah that is smart to use a counter to subtract from but the counter number should have come from the value in $4000, if I'm not mistaken.

    well good luck on the test, I love this assembly too.

  7. #7

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Yes you are right the counter value should have come from the memory location. I dont think I could get that little bit working, so for the sake of soemthing quite petty in comparison to the overall question I just hardcoded the value.

    I'll be working on that today though.

    Its really cool this assembly... you can do so much.
    And it also explains a lot about programming... like what a compiler is, what a linker is, what machine code is, how Dim X As Long is executed in a CPU etc.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8
    Zaei
    Guest
    It will make you a better programmer by far. Next you can go and learn C++ =P.

    Z.

  9. #9

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Interesting route im taking,

    mIRC Scripting -> VB -> Java -> Assembly -> C++

    Hmmm a little muddled up one might say
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

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



Click Here to Expand Forum to Full Width