0

I need to write program that the user enters an unsigned number and the display will indicate if this number is odd, even or equal to zero

The problem I got is at any number it display Z in 7segment, which is not correct So, I do not where is the problem. Can any one help me to fix the problem.

LEDS       EQU     $E00010                 ;LEDS adress
SW         EQU      $E00012                 ;switch address
BU         EQU     $E00014                 ;button address

one        EQU      $E00000                 ;7 segment display address 1

two        EQU     $E00002
three      EQU     $E00004
four       EQU      $E00006
five        EQU     $E00008
six         EQU     $E0000A
seven       EQU     $E0000C
eight       EQU     $E0000E
             ORG     $400                    ;start of program area
START



Loop

         MOVE.B  D0,LEDS     
            MOVE.B  SW,D1
           MOVE.B  BU,D2
            MOVE.B  #0,D3  
           MOVE.B  #0,D0                    ; LEDS is off
           MOVE.B  #0,one                   ;7 segment is off
           MOVE.B   #0,two
            MOVE.B  #0,three
            MOVE.B  #0,four
            MOVE.B  #0,five
            MOVE.B  #0,six
            MOVE.B  #0,seven
            MOVE.B  #0,eight    
            MOVE.B  #%1101101,one             ;display S  on 7 segment 
            NOT.B   D2                      ; flip value of button
            CMP.B   #%00000001,D2         ;if the right button is clicked
            BNE     Loop                
            MOVE.B  D1,D0     ;THEN MOVE SWICH VALUES ON LEDS
            MOVE.B  D0,LEDS
            MOVE.B  #0,one
            CMP.B   D1,D3
            BEQ     ZERO
            DIVS.W  #2,D1                   
            CMP.B    D1,D3                  ;IF D1=D3 WHICH ZERO, THEN
            BEQ     EVEN                      ; NUMBER IS ODD
            BRA     ODD                    ; ELSE DISPLAY EVEM
EVEN          MOVE.B  #%1111001,one            
ODD         MOVE.B  #%0111111,one          
ZERO         MOVE.B    #%1011001,one 

            END      START  
nas2016
  • 15
  • 5
  • After you branch to EVEN, you drop through to ODD then to ZERO, so you might as well always got to ZERO immediately. – stark Jan 27 '17 at 21:44
  • @ stark: thanks , but I did not get what do you mean could please explain int more? do you mean in EVEN I have put another line which is { BRA Loop} ?? – nas2016 Jan 28 '17 at 00:09
  • 1
    BTW, you don't need to test for odd/evenness by `DIV`. When you split numerical value into binary formatting, each bit has value 2^i. For (1 <= i) that means, that the value is divisible by 2, because 2^i = 2 * 2^(i-1). The only exception is 2^0 = 1, this one is not divisible by 2. That means, that the whole value consist of all divisible-by-two powers of two (1 <= i), except the least significant bit, which has value 1. So any number converted to binary form is odd if and only if the least significant bit is set. To test least significant bit in reg. you can use `BTST #0,D1` `BEQ D1_is_even`. – Ped7g Jan 28 '17 at 04:27
  • (values in registers are internally (in HW) stored in bits, so they are de facto converted into binary representation and as you have instruction capable to manipulate particular individual bits of register value, you can work with that binary representation directly, without any further conversion or preparations) – Ped7g Jan 28 '17 at 04:31
  • @Ped7g: thanks I appreciate your help, now it's clear to me where is the mistake – nas2016 Jan 28 '17 at 07:30

1 Answers1

0

This:

BEQ     EVEN                      ; NUMBER IS ODD

Looks like it should be:

BEQ     ODD                      ; NUMBER IS ODD
Ville Krumlinde
  • 7,021
  • 1
  • 33
  • 41