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

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Dec 06, 2016 8:28 pm 
Offline

Joined: Tue Dec 06, 2016 7:55 pm
Posts: 1
Hi Everyone,

I have an assignment that I'm really struggling with. The goal is to take a negative or positive number from the user and then either display all the even numbers in the array or all the odd numbers in the array.

Initialize an array [1, 7, 13, 0, 11, 24, 8]. Then,
1) Load a signed number from the keyboard. (20 pts.)
2) If the number is negative, print out odd elements in the array. Otherwise, print out even elements. Do not forget the commas. (30 pts.)
Desired output:
1, 7, 13, 11
Or:
0, 24, 8

My code is below, I am unsure A) how to check whether the input is negative or positive to then branch it to display even/odd numbers B) how to find the even/odd numbers in array (I think for odd numbers I had to divide by 2 and swap but I don't know where to put it and if I am even right)

Any help would be appreciated!

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

    LEA ARRAY, A0
   
    LEA MESSAGE, A1
    MOVE #14, D0
    TRAP #15
   
    MOVE.B #4, D0   ;USER INPUT
    TRAP #15
   
    CMP.L #0,D1    ;LOOKING FOR NEG
    BLT ODDNUM
   
   
    ;BRA END

ODDNUM
    CMP.L #ARRAYSIZE, D3    ;NOT END OF ARRAY LOOP
    ;BHS ENDL
   
    CMP.L #4, D3
    BLE CHECK
   
    LEA COMMA, A1
    MOVE.B #14, D0
    TRAP #15
 
CHECK
    CLR.L D1
    MOVE (A0,D3),D1
   
    MOVE.B #15, D0
    MOVE.B #10, D2
    TRAP #15
   
    ADD.L #4,D3
    BRA ODDNUM


END 
 
ENDL
 

    SIMHALT             ; halt simulator

CR   EQU   $0D
LF   EQU   $0A

ARRAY DC.L 1,7,13,0,11,24,8
ARRAYSIZE EQU 14
SPACE   DC.B ' ',0
MESSAGE DC.B 'ENTER A SIGNED NUMBER (NEG FOR ODD, POS FOR EVEN): ', 0
COMMA DC.B  ',',0

    END    START        ; last line of source






Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 07, 2016 12:14 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 DIVU instruction returns the modulus in the upper word of the result.
number mod 2 is 0 if number is even and 1 if number is odd.

Code:
* Test for even or odd in D0
    divu    #2,D0
    swap    D0
    tst.w   D0
    beq     even
* the number in D0 was odd   
* put code here to handle odd values
    bra     next
* the number in D0 was even
* put code here to handle even values
even

next

_________________
Prof. Kelly


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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:  
Powered by phpBB® Forum Software © phpBB Group