EASy68K  
It is currently Tue Oct 22, 2019 4:50 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu May 26, 2011 1:42 pm 
Offline

Joined: Thu May 26, 2011 9:00 am
Posts: 10
part1:
Allow the user to enter a sequence of up to 100 integers, with values from 0 to 255.You may assume that the input integers are all in that format. You must echo each integer to the screen and store it in memory as it is typed. The user will press "Enter" to terminate the input.

part2:
Once the user has terminated the input, you must loop through the sequence and keep the position of the smallest integer in the sequence. In the case of a multiple occurrence of the same smallest integer, you must keep the position of the first of the smallest integers. Display that position to the screen as in:
The position of the smallest element is 55

part3:
You are required to implement subroutines and parameter passing for this requirement, as follows:
Write a subroutine to return either the smallest or the largest integer in the sequence.You must pass which one, either smallest or largest, as a parameter to the subroutine on the stack. You must return the position also on the stack. Display these positions:
The position of the smallest element is 55 and the position of the largest
element is 17

there are 3 part ...does anyone can help me?


Last edited by wangyimang on Thu May 26, 2011 5:44 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2011 4:27 pm 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
This sounds a lot like homework so no.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2011 4:46 pm 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
Post the code you have written/tested so far.

Provide the complete test case, with the numbers used. The second, and third parts seem to refer to a list of specific numbers you have not provided.

Go look through the EASy68K example programs to gain some familiarity with the code, and refer to your text books, and recommended reading list, for better coverage.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2011 5:47 pm 
Offline

Joined: Thu May 26, 2011 9:00 am
Posts: 10
thank you for your reply,
the code written so far is below
Code:
        ORG           $1000
SIZE     equ           4              ; data size (4 bytes for long word)

START:                                ; first instruction of program

         lea          array1,A0       ; pointer to array
   
         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
   
        lea           result,A1       ; pointer to string
        move.b        #13,D0          ; display result
        trap          #15
   
        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
       
        MOVE.B      #9,D0
        TRAP        #15                 ; halt simulator

* Variables and Strings
array1  ds.l        10  ; 10 long word array
prompt  dc.b        'Enter numbers: ',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




Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2011 5:49 pm 
Offline

Joined: Thu May 26, 2011 9:00 am
Posts: 10
it seems to satisfy part1, but I rellay stuck at rest of them, can you help me a little, I need rush this due to 27th 11:00pm. thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2011 5:53 pm 
Offline

Joined: Thu May 26, 2011 9:00 am
Posts: 10
a list of specific numbers maybe like: 23, 33, 59, 55, 112 for instance, so the smallest integer in this case is number 23


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2011 7:57 pm 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
wangyimang wrote:
it seems to satisfy part1, but I rellay stuck at rest of them, can you help me a little, I need rush this due to 27th 11:00pm. thanks in advance

Well not really.

Your array is only 10 deep, the question asks for 100.

There is no looping to take more than 1 number of input.

You will need to input multiple numbers, and decide on a number that should terminate the input. Presumably something greater than 255, or less than 0.

You don't initialize D2, so "move.l D1,(A0,D2)" is a little pointless, you also don't advance D2 for subsequent numbers. I'd use "MOVE.L D1,(A0)+" to advance into the array. And later reload A0 in the results phase.

You will need to output multiple numbers, either having a count of numbers, or a marker in the array.

For the subsequent parts a count might be useful.

Assign two registers (min,max) beyond the scope of the numbers allowed for input, enumerate through the list comparing the current number to the min/max values, have two other register hold the index of the min/max elements within the array. This will test your skill with registers, comparisons, and branching.

I think I've posted a min/max example before, and discussed parameter passing on the stack. Suggest you dig through the forum posts.

That's your deadline, I have my degree already.


Top
 Profile  
 
PostPosted: Fri May 27, 2011 1:07 am 
Offline

Joined: Thu May 26, 2011 9:00 am
Posts: 10
does any one can give me a example find two registers (min,max)


thank


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2011 6:37 am 
Offline

Joined: Thu May 26, 2011 9:00 am
Posts: 10
Clive, could you help me to do this, it has two day more time, I rellay dont know how to do it...


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2011 7:30 pm 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
I will help you, but I'm not going to do your assignment for you.

Follow my earlier suggestions.

If you can get some of your own code that's 85-90% working, I'll help you fix that.

You can use CMP and BCC,BCS, or Bxx in general to compare and make decisions about whether one register is bigger/smaller than another. If you use D2 as an index into the array, you can start at 0, and increment by 4 to step over LONG words. To convert that to an enumerated index, divide that by 4 and add 1. So 0 becomes 1, 4 becomes 2, 8 becomes 3, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2011 8:17 am 
Offline

Joined: Thu May 26, 2011 9:00 am
Posts: 10
clive can you help me to fix this

Code:
         ORG           $1000
SIZE     equ           4              ; data size (4 bytes for long word)

START:   move.l   #$7fffe,sp
   move.l   #data,a1
   move.b   #100.d2
   clr.b   d7
loop   add.b   (a1)+,d7
   sub.b   #1,d2
   bne   loop
   move.b   #9,d0
   trap   #15
   org   $1200
data   dc.b   4
   dc.b   12
   dc.b   7
   dc.b   1
   end                            ; first instruction of program

         lea          array1,A0       ; pointer to array
   
         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
   
        lea           result,A1       ; pointer to string
        move.b        #13,D0          ; display result
        trap          #15
   
        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
       
        MOVE.B      #9,D0
        TRAP        #15                 ; halt simulator
       
data   equ   $6000
program   equ   $4000
length   ds.w   1

maxnum   ds.w   1
   org   program
   movea.l   start,a0
   moveq   #0,d0
   move.w   length,d1
   beq.s   done
loop   move.w   (a0)+,d2
   cmp.w   d2,d0
   bcc.s   looptest
   move.w   d2,d0
looptest   subq.w   #1,d1
   bne   loop
done   move.w   d0,maxnum
   rts

* Variables and Strings
array1  ds.l        10  ; 10 long word array
prompt  dc.b        'Enter numbers: ',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



     



Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 2:55 am 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
Well that was pretty hopeless.

Code:
        ORG     $1000

START:  move.l  #$7ffe,sp

        lea     prompt,A1       ; pointer to string
        move.b  #13,D0          ; display prompt
        trap    #15

        lea     array1,A0       ; pointer to array
        clr.l   d2
inloop:
        move.b  #4,D0           ; read number from keyboard into D1.L
        trap    #15

        cmp.l   #0,d1           ; out of range (0..255)
        blt     indone
        cmp.l   #255,d1
        bgt     indone

        move.l  d1,(a0,d2)      ; store number to array at index D2

        move.l  d2,d1           ; convert offset to index
        lsr.l   #2,d1           ; divide by 4
        addq.l  #1,d1           ; 1..n
        move.b  #3,d0           ; display number
        trap    #15

        lea     result,A1       ; pointer to string
        move.b  #14,D0          ; display cr lf
        trap    #15

        move.l  (a0,d2),d1
        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

        addq.l  #4,d2           ; advance LONG offset
        cmp.l   #400,d2         ; or 100 LONGs
        bne     inloop
indone:

        move.l  #256,d3         ; smallest (everything less than 256 in list)
        move.l  #400,d4         ; smallest element index
        clr.l   d5              ; current index
minloop:
        cmp.l   (a0,d5),d3
        bcs     minnext
        move.l  (a0,d5),d3
        move.l  d5,d4
minnext:
        addq.l  #4,d5           ; next index
        cmp     d5,d2           ; end of list
        bne     minloop

; d3 = smallest value
; d4 = smallest index * 4

        lea     minnum,A1       ; pointer to string
        move.b  #14,D0          ; display string
        trap    #15

        move.l  d3,d1           ; smallest number
        move.b  #3,d0           ; display number
        trap    #15

        lea     crlf,A1         ; pointer to string
        move.b  #14,D0          ; display cr lf
        trap    #15

        lea     minidx,A1       ; pointer to string
        move.b  #14,D0          ; display string
        trap    #15

        move.l  d4,d1           ; convert offset to index
        lsr.l   #2,d1           ; divide by 4
        addq.l  #1,d1           ; 1..n
        move.b  #3,d0           ; display number
        trap    #15

        lea     crlf,A1           ; pointer to string
        move.b  #14,D0            ; display cr lf
        trap    #15

        move.b  #9,d0           ; halt simulator
        trap    #15

* Variables and Strings
array1  ds.l        100  ; 100 long word array
prompt  dc.b        'Enter numbers: (0-255), -1 to quit',0    ; null terminated string
result  dc.b        ' : ',0  ; null terminated string
minnum  dc.b        'Minimum number : ',0
minidx  dc.b        'Minimum index  : ',0
crlf    dc.b         $d,$a,0                 ; carriage return, line feed, null

        END          START       ; last line of source


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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