EASy68K  
It is currently Sun Dec 08, 2019 3:57 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Feb 17, 2010 11:21 am 
Offline

Joined: Wed Feb 17, 2010 11:19 am
Posts: 1
Using the example code i found on here,

Code:
*-----------------------------------------------------------
* Program    : Array programming
* Written by : Chuck Kelly
* Date       : April, 2009
* Description: Get 10 numbers from keyboard, store them in
*              an array then display them from the array.
*-----------------------------------------------------------
    ORG $1000
SIZE    equ     4   ; data size (4 bytes for long word)

START:              ; first instruction of program

    * read 10 numbers from keyboard and store in array
    lea array1,A0           ; pointer to array
   
    for D2 = #0 to #9*SIZE by #SIZE do.s  ; loop 10 times
        lea     prompt,A1   ; pointer to string
        move.b  #13,D0      ; display prompt
        trap    #15
       
        move.b  #4,D0       ; read number from keyboard into D1.L
        trap    #15
               
        move.l  D1,(A0,D2)  ; store number to array at index D2
    endf
   
    lea     result,A1       ; pointer to string
    move.b  #13,D0          ; display result
    trap    #15
   
    * display numbers from array
    for D2 = #0 to #9*SIZE by #SIZE do.s  ; loop 10 times
        move.l  (A0,D2),D1  ; get number from array at index D0
        move.b  #3,D0       ; display number in D1.L
        trap    #15
       
        lea     crlf,A1     ; pointer to string
        move.b  #14,D0      ; display cr lf
        trap    #15
    endf
       
    MOVE.B  #9,D0
    TRAP    #15     ; halt simulator

* Variables and Strings
array1  ds.l    10  ; 10 long word array
prompt  dc.b    'Enter a number: ',0    ; null terminated string
result  dc.b    'Your numbers are: ',0  ; null terminated string
crlf    dc.b    $d,$a,0                 ; carriage return, line feed, null

    END START       ; last line of source
   


I am struggling to work out how I would get the program to print the contents of the array in reverse order, any help greatly appreciated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 17, 2010 1:09 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1109
Restructure the second FOR loop to make it loop from the last character in the array to the first.

Your question is about programming logic, not about 68000 programming.

The following is an excerpt from a lecture I give my students on a daily basis:

Logic first.
Logic first.
Logic first.
:idea1:

And while I'm lecturing, this is the student response:
:sleepy2:

Then when they ask me for :help:

This is my response:
:dontknow:

_________________
Prof. Kelly


Last edited by profkelly on Fri Feb 17, 2012 2:51 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Help
PostPosted: Fri Feb 17, 2012 2:46 pm 
Offline

Joined: Fri Feb 17, 2012 11:12 am
Posts: 1
What do you mean restructure the second FOR loop to make it loop from the last character in the array to the first?

I am new to this can you tell me what to change please?

I will be grateful.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2012 3:00 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1109
I don't want to sound condescending in my responses to the first question or your question so please take this answer as that of a teacher trying to help a student.

I see a lot of students in Assembly Language who have weak programming logic skills. Those students can sometimes get through a lower level programming class that utilizes a high level language by finding example programs in the book or online and make changes to the code over and over until they get something that produces the desired result. That same approach will usually fail miserably in assembly language. (Which is one of the reasons I think every computer science degree should require it.)

Work out the logic required to solve the problem. Use flow charts or pseudo code to describe the logic. Code the solution in a high level language if necessary. Do not attempt to code the program in Assembly Language until you have a thorough grasp on the logic.

_________________
Prof. Kelly


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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