EASy68K  
It is currently Mon Mar 27, 2017 8:25 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Thu Nov 06, 2014 6:58 pm 
Offline

Joined: Thu Nov 06, 2014 6:31 pm
Posts: 6
Hello,

I would like to first put it out there that I am a beginner to assembly language and 68000.. I am trying to initialize an array and then display it. I believe that I've initialized the array correctly but I have no idea how to display it.

Here's my code so far:

Code:
    ORG    $1000
START:                  ; first instruction of program

* Put program code here
ARRAY   DS.B    10
        LEA     Array,A0
        MOVE.B  #5,0(A0)
        MOVE.B  #7,1(A0)
        MOVE.B  #12,2(A0)
        MOVE.B  #3,3(A0)
        MOVE.B  #8,4(A0)
        MOVE.B  #21,5(A0)
        MOVE.B  #11,6(A0)
        MOVE.B  #1,7(A0)
        MOVE.B  #2,8(A0)
        MOVE.B  #16,9(A0)



* Put variables and constants here

    END    START        ; last line of source


Do I somehow move the array to D0 then use TRAP #15?


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 07, 2014 4:41 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1036
Location: Monroe County Community College, Monroe Michigan, U.S.A.
bandora wrote:
Note the modification to the code.
Code:
    ORG    $1000
START:                  ; first instruction of program

* Put program code here
        LEA     Array,A0
        MOVE.B  #5,0(A0)
        MOVE.B  #7,1(A0)
        MOVE.B  #12,2(A0)
        MOVE.B  #3,3(A0)
        MOVE.B  #8,4(A0)
        MOVE.B  #21,5(A0)
        MOVE.B  #11,6(A0)
        MOVE.B  #1,7(A0)
        MOVE.B  #2,8(A0)
        MOVE.B  #16,9(A0)


* Put variables and constants here
ARRAY   DS.B    10      ; NOTE! The array was moved out of the code area

    END    START        ; last line of source


Do I somehow move the array to D1 then use TRAP #15?

Yes, move the data into D0 then use something like trap 3.
Code:
        LEA ARRAY,A0
        MOVE.B #3,D0        ; trap task 3, display signed number from D1
        MOVE.B (A0)+,D1     ; put number from array into D1
        TRAP #15            ; display number in D1

_________________
Prof. Kelly


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 10, 2014 12:45 am 
Offline

Joined: Thu Nov 06, 2014 6:31 pm
Posts: 6
Hello,

Thanks for the help! :D

I also have another quick question if you don't mind (I'm just nitpicking at this point, but I am just curious on how to do it).

Basically I got it to show all the values in the array with brackets and commas (between each value). But At the end there's an extra comma and I tried to do an iterator for the comma but I didn't know how to implement it).

So basically an example array output is: [5,7,3,12,13,16,] <--- has that extra comma at the end.

Here's my code so far:

Code:
*-----------------------------------------------------------
* Title      :
* Written by :
* Date       :
* Description:
*-----------------------------------------------------------
    ORG    $1000
START:                  ; first instruction of program

* Put program code here
        LEA     Array,A0
        MOVE.B  #10,D2
        ;MOVE.B #9,D3   ; Iterator for how many commas are going to be there
        MOVE.B  #5,0(A0)
        MOVE.B  #7,1(A0)
        MOVE.B  #12,2(A0)
        MOVE.B  #3,3(A0)
        MOVE.B  #8,4(A0)
        MOVE.B  #21,5(A0)
        MOVE.B  #11,6(A0)
        MOVE.B  #1,7(A0)
        MOVE.B  #2,8(A0)
        MOVE.B  #16,9(A0)
       
            ;LEA ARRAY,A0
        LEA     BRACKET1,A1
        MOVE.B  #14,D0
        TRAP    #15

LOOP    MOVE.B  #3,D0        ; trap task 3, display signed number from D1
        MOVE.B  (A0)+,D1     ; put number from array into D1
        TRAP    #15            ; display number in D1
       
        LEA     COMMA,A1
        MOVE.B  #14,D0
        TRAP    #15
        ;SUB.B  #1,D3     
       
        SUB.B   #1,D2
        BNE     LOOP
       
        LEA     BRACKET2,A1
        MOVE.B  #14,D0
        TRAP    #15
     


* Put variables and constants here
ARRAY       DS.B    10      ; NOTE! The array was moved out of the code area
BRACKET1    DC.B    '[',0
COMMA       DC.B    ',',0
BRACKET2    DC.B    ']',0

    END    START        ; last line of source


Thanks in advance,


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 10, 2014 2:57 pm 
Offline

Joined: Thu Nov 06, 2014 6:31 pm
Posts: 6
Also, iterating by 1 is (A0)+,D1... How about if I want to iterate by 2 or more, like is there a way to go by 2?

For example: Go from index 0 to index 2 then to index 4.. etc.

Is it something like 2(A0)+,D1? But wouldn't that mean start from index 2 and iterate up by one?

The problem is that I can't find any resources that I can read about those specific problems that I'm experiencing. I have an idea on how to implement it, just don't know how to do it in this language. xD

Any help/guidance is much appreciated!


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 10, 2014 5:07 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1036
Location: Monroe County Community College, Monroe Michigan, U.S.A.
Code:
    ORG    $1000
START:                  ; first instruction of program

* Put program code here
        LEA     ARRAY,A0
        MOVE.B  #ARRAY_SIZE,D2
        LEA     BRACKET1,A1
        MOVE.B  #14,D0
        TRAP    #15

LOOP    MOVE.B  #3,D0           ; trap task 3, display signed number from D1
        MOVE.B  (A0)+,D1        ; put number from array into D1
        TRAP    #15             ; display number in D1
       
        IF.B D2 <HI> #1 THEN    ; if not end of array
            LEA     COMMA,A1    ; display comma
            MOVE.B  #14,D0
            TRAP    #15
        ENDI
       
        SUB.B   #1,D2
        BNE     LOOP
       
        LEA     BRACKET2,A1
        MOVE.B  #14,D0
        TRAP    #15
     

* Put variables and constants here
ARRAY       DC.B    5, 7, 12, 3, 8, 21, 11, 1, 2, 16
ARRAY_SIZE  EQU     *-ARRAY
BRACKET1    DC.B    '[',0
COMMA       DC.B    ',',0
BRACKET2    DC.B    ']',0

    END    START        ; last line of source


The auto increment syntax (A0)+ uses the operation size to determine how much to add.

MOVE.B #1,(A0)+ ; add 1 byte
MOVE.W #1,(A0)+ ; add 2 bytes

_________________
Prof. Kelly


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 11, 2014 6:24 am 
Offline

Joined: Thu Nov 06, 2014 6:31 pm
Posts: 6
Thank you for all your help so far Prof. Kelly!

Would you mind letting me know if I understood what you've done correctly?

The
Code:
MOVE.B #ARRAY_SIZE,D2
is basically a dynamic array which replaces the manually allocated memory slots that's on my code
Code:
MOVE.B 10,D2
right?

But, could you let me know what this means?
Code:
ARRAY_SIZE  EQU     *-ARRAY
(in particularly what *-ARRAY is?)

And finally in the first line of the IF statement does <HI> mean end of array? What is (#1)'s role in this? Is it saying that last element of array?

Sorry for bombarding you with questions, but I just want to understand it better! :)

Thanks again for all your help so far!!

EDIT: For iterating by two, I ended up doing this:
Code:
        MOVE.B  (A1)+,D1
        ADDA    #1,A1
        TRAP    #15


Which as far as I understand it, I could've also done this:

Code:
        MOVE.B  (A1),D1
        ADDA    #2,A1
        TRAP    #15


EDIT: Never mind on the dynamic array thing that I've said earlier, we're still manually allocating 10 slots by doing
Code:
ARRAY    DS.B    10


So, I guess I don't fully understand what you did with the ARRAY_SIZE.


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 11, 2014 1:48 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1036
Location: Monroe County Community College, Monroe Michigan, U.S.A.
bandora wrote:
The
Code:
MOVE.B #ARRAY_SIZE,D2
is basically a dynamic array which replaces the manually allocated memory slots that's on my code
Code:
MOVE.B 10,D2
right?

But, could you let me know what this means?
Code:
ARRAY_SIZE  EQU     *-ARRAY
(in particularly what *-ARRAY is?)
My code declares and initializes the array in one step as opposed to reserving space for the array and then loading the values into it, which is what your code does. ARRAY_SIZE EQU *-ARRAY declares the constant ARRAY_SIZE. *-ARRAY calculates the number from the current address '*' minus the address of ARRAY which results in the size of the array.

bandora wrote:
And finally in the first line of the IF statement does <HI> mean end of array? What is (#1)'s role in this? Is it saying that last element of array?
<HI> means HIgher. Refer to the EASy68K Help for detailed information on all of the syntax and features. Context sensitive help is available for most keywords. Just put the cursor on the word and press F1.

_________________
Prof. Kelly


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 11, 2014 9:00 pm 
Offline

Joined: Thu Nov 06, 2014 6:31 pm
Posts: 6
Thank you for you help again Prof. Kelly.

And thank you for letting me know about the context sensitive help! (I wasn't aware of that feature! :D)

I have one last question for you (I promise this time.. xD)

How can I utilize both previous loops that I've done into a new loop.. Like I am trying to add every two numbers in the array, and my idea was to have the EVEN and ODD loops run in this new loop and take every element from those two loops and add them together until I reach the end of both loops. (That's my idea of adding every two numbers in an array, if there's an easier way, I'm open for suggestions.)

This is my code so far:

Code:
START:  ORG     $1000           ; first instruction of program

* Put program code here
*------ Initialization ------*
        CLR.B   D0
        LEA     Array,A0
        MOVE.B  #ARRAY_SIZE,D2
        MOVE.B  #5,D3
        MOVE.B  #5,0(A0)
        MOVE.B  #7,1(A0)
        MOVE.B  #12,2(A0)
        MOVE.B  #3,3(A0)   
        MOVE.B  #8,4(A0)   
        MOVE.B  #21,5(A0)
        MOVE.B  #11,6(A0)
        MOVE.B  #1,7(A0)
        MOVE.B  #2,8(A0)
        MOVE.B  #16,9(A0)       ; Array: [5, 7, 12, 3, 8, 21, 11, 1, 2, 16]
*----------------------------*

        LEA     ARRAYMSG,A1
        MOVE.B  #14,D0
        TRAP    #15

*--- Show the whole array ---*
        LEA     BRACKET1,A1     ; Initialize left bracket
        MOVE.B  #14,D0
        TRAP    #15             ; Display left bracket
       

LOOP    MOVE.B  #3,D0           ; Trap task 3, display signed number from D1
        MOVE.B  (A0)+,D1        ; Put number from array into D1
        TRAP    #15             ; Display number in D1
               
        IF.B D2 <HI> #1 THEN    ; If not end of array
            LEA     COMMA,A1    ; Display comma
            MOVE.B  #14,D0
            TRAP    #15
        ENDI
       
        SUB.B   #1,D2           ; Iteration
        BNE     LOOP            ; Doesn't match current criteria = loop, does match = end loop
       
        LEA     BRACKET2,A1     ; Initialize right bracket
        MOVE.B  #14,D0
        TRAP    #15             ; Display right bracket
*----------------------------*

        LEA     NEWLINE,A1
        MOVE.B  #14,D0
        TRAP    #15

        LEA     ADDMSG,A1
        MOVE.B  #14,D0
        TRAP    #15

*--- Addition of even indexes should be: 5, 12, 8, 11, 2 = 38
        LEA     EVENMSG,A1
        MOVE.B  #14,D0
        TRAP    #15
 
        LEA     ARRAY,A0
        CLR     D4
     
EVEN    MOVE.B  #3,D0
        MOVE.B  (A0)+,D1    ; Iterate by 1               -  This could've been done like:   MOVE.B (A1),D1       
        ADDA    #1,A0       ; Then iterate by another 1  -  This line would be              ADDA   #2,A1
        ADD.B   D1,D4       ; Add number with the previous
        MOVE.B  D4,D1       ; The previous number
       
        SUB.B   #1,D3       ; Iteration
        BNE     EVEN        ; Loop EVEN
        TRAP    #15         ; Display the total of added numbers
*----------------------------*

        LEA     NEWLINE,A1
        MOVE.B  #14,D0
        TRAP    #15

*--- Addition of odd indexes should be: 7, 3, 21, 1, 16 = 48
        LEA     ODDMSG,A1
        MOVE.B  #14,D0
        TRAP    #15
       
        LEA     ARRAY,A0
        MOVE.B  #5,D3
        CLR     D4          ; Clear D4 so we can move the added numbers to that data register

ODD     MOVE.B  #3,D0
        MOVE.B  1(A0),D1    ; Start with the 2nd index
        ADDA    #2,A0       ; Then iterate by 2
        ADD.B   D1,D4       ; Add number with the previous
        MOVE.B  D4,D1       ; Move that added number back for display
       
        SUB.B   #1,D3       ; Iteration
        BNE     ODD         ; Loop ODD
        TRAP    #15         ; Display the added numbers
*----------------------------*

        LEA     NEWLINE,A1
        MOVE.B  #14,D0
        TRAP    #15
       
        LEA     TWONUMSMSG,A1
        MOVE.B  #14,D0
        TRAP    #15

*--- Addition of every two numbers shoud be: (5, 7) = 12 , (12, 3) = 15 , (8, 21) = 29 , (11, 1) = 12 , (2, 16) = 18
        LEA     ARRAY,A0
        MOVE.B  #ARRAY_SIZE,D2
        CLR     D4              ; Clear D4 so we can move the added numbers to that data

TWONUMS MOVE.B  #3,D0
        MOVE.B  (A0)+,D1    ; Iterate by 1
        ADD.B   D1,D4       ; Add number with the previous
        MOVE.B  D4,D1       ; The previous number
        TRAP    #15
       
        SUB.B   #1,D2       ; Iteration
        BNE     TWONUMS     ; Loop TWONUMS
        ;TRAP    #15        ; Display the total of added numbers
       
*----------------------------*

       
* Put variables and constants here
CR          EQU     $0D
LF          EQU     $0A
ARRAY       DS.B    10          ; Allocate 10 bytes for array
ARRAY_SIZE  EQU     *-ARRAY
ARRAYMSG    DC.B    'Array: ',0
BRACKET1    DC.B    '[',0
COMMA       DC.B    ',',0
BRACKET2    DC.B    ']',CR,LF,0
ADDMSG      DC.B    'Different addition methods: ',CR,LF,0
ODDMSG      DC.B    'Addition of values in odd indexes: ',0
EVENMSG     DC.B    'Addition of values in even indexes: ',0
TWONUMSMSG  DC.B    'Addition of every two elements:',CR,LF,0
NEWLINE     DC.B    '',CR,LF,0


    END    START            ; last line of source


EDIT: So, in the new loop, I would need to branch (BRA) out to the EVEN loop then have it spit out the first .. bah, nvm, if I do it this way, then it will mess up what I've done before (calculating the even indexes.. etc).

EDIT2: A friend of mine told me about using the Z-flag to check the indexes, then if the Z-flag is 0 then BNE to another label that calculates the current value of the current index with the previous one. Bah! But, I need to fully understand that! :(

EDIT3: Or maybe, I could have the array from the EVEN loop stored in a different address, and the same thing for ODD then add those two together..


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 12, 2014 2:38 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1036
Location: Monroe County Community College, Monroe Michigan, U.S.A.
The sum of the even array numbers is calculated in D6 and the odd array numbers in D7. D5 is the array index.
Code:
*-----------------------------------------------------------
* Title      :
* Written by :
* Date       :
* Description:
*-----------------------------------------------------------
    ORG    $1000
START:                  ; first instruction of program

* Put program code here
        CLR.L   D1
        CLR.L   D5      ; D5 is array index
        CLR.L   D6      ; even sum in D6
        CLR.L   D7      ; odd sum in D7
        LEA     ARRAY,A0
        MOVE.B  #ARRAY_SIZE,D2
        LEA     BRACKET1,A1
        MOVE.B  #14,D0
        TRAP    #15

LOOP    MOVE.B  #3,D0           ; trap task 3, display signed number from D1
        MOVE.B  (A0,D5),D1      ; put number from array into D1
        TRAP    #15             ; display number in D1
        BTST    #0,D5           ; test bit 0
        IF <EQ> THEN            ; if even index
            ADD.W D1,D6         ; add D1 to even sum
        ELSE                    ; else, odd index
            ADD.W D1,D7         ; add D1 to odd sum
        ENDI
        ADD     #1,D5           ; increment array index
       
        IF.B D2 <HI> #1 THEN    ; if not end of array
            LEA     COMMA,A1    ; display comma
            MOVE.B  #14,D0
            TRAP    #15
        ENDI
       
        SUB.B   #1,D2
        BNE     LOOP
       
        LEA     BRACKET2,A1
        MOVE.B  #14,D0
        TRAP    #15
     
        SIMHALT                 ; halt the simulator

* Put variables and constants here
            DS.L    0           ; force array to start on even address
ARRAY       DC.B    5, 7, 12, 3, 8, 21, 11, 1, 2, 16
ARRAY_SIZE  EQU     *-ARRAY
BRACKET1    DC.B    '[',0
COMMA       DC.B    ',',0
BRACKET2    DC.B    ']',0

    END    START        ; last line of source

_________________
Prof. Kelly


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group