+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Member level 1
    Points: 540, Level: 4

    Join Date
    Jul 2012
    Posts
    38
    Helped
    0 / 0
    Points
    540
    Level
    4

    'Comparison' in assembly language

    Hello,

    I want to prepare a assembly program which will compare more than 2 numbers. Actually i want to send a message to particular mobile number if speed exceeds more than say 6 km/hr

    suppose that there are 3 digit numbers (till 999). now if speed exceeds above 6 km/hr then it should jump to "Message sending routine". after executing that it should come back to the comparison. how should i implement in program?
    So if i consider only unit's place then it should be compared with '6'.. if number at unit's place is greater than '6' then it will jump to "Message sending routine". How to do this?? i need example of a such program..

    thank you :)

    •   AltAdvertisment

        
       

  2. #2
    Member level 2
    Points: 832, Level: 6

    Join Date
    Feb 2013
    Posts
    42
    Helped
    5 / 5
    Points
    832
    Level
    6

    Re: 'Comparison' in assembly language

    Assembler for what ?

    Z80 / 8080 / 8085 / PIC 8 bit / Pic 16 bit / Pic 32 bit / 8051 / MSP 430 / ARM / IBM-470 / Cray.

    I would sugest that you define the processor as 1st step, then somebody can help



  3. #3
    Super Moderator
    Points: 50,431, Level: 54

    Join Date
    Apr 2011
    Location
    Minneapolis, Minnesota, USA
    Posts
    12,402
    Helped
    2464 / 2464
    Points
    50,431
    Level
    54

    Re: 'Comparison' in assembly language

    Maybe subtract your desired number (which is 6), then do:

    BEQ (branch if equal to zero)
    BNE (if not equal)
    BMI (if minus)
    BLT (if less than)
    BGT (if greater than)

    The 'branch' command jumps forward or backward the stated number of bytes (in two's complement).



  4. #4
    Member level 1
    Points: 540, Level: 4

    Join Date
    Jul 2012
    Posts
    38
    Helped
    0 / 0
    Points
    540
    Level
    4

    Re: 'Comparison' in assembly language

    Quote Originally Posted by ebclr View Post
    Assembler for what ?

    Z80 / 8080 / 8085 / PIC 8 bit / Pic 16 bit / Pic 32 bit / 8051 / MSP 430 / ARM / IBM-470 / Cray.

    I would sugest that you define the processor as 1st step, then somebody can help
    oh sorry i forgot that... its AT89C51 controller..

    - - - Updated - - -

    Quote Originally Posted by BradtheRad View Post
    Maybe subtract your desired number (which is 6), then do:

    BEQ (branch if equal to zero)
    BNE (if not equal)
    BMI (if minus)
    BLT (if less than)
    BGT (if greater than)

    The 'branch' command jumps forward or backward the stated number of bytes (in two's complement).
    can you please give me some more info? :o



    •   AltAdvertisment

        
       

  5. #5
    Super Moderator
    Points: 50,431, Level: 54

    Join Date
    Apr 2011
    Location
    Minneapolis, Minnesota, USA
    Posts
    12,402
    Helped
    2464 / 2464
    Points
    50,431
    Level
    54

    Re: 'Comparison' in assembly language

    The Branch command works the opposite of an IF structure.

    It tests for a condition in the register, and if the condition is satisfied then it will cause execution to branch around your message routine. The number of bytes it skips forward or backward must be less than 127.

    That is how it worked with my VIC-20 assembly code (using the 6502 microprocessor). Your AT89C51 may use a different command.

    You can also put your message routine in a separate block of memory, and JUMP to its address. Then Jump back. Of course this requires that you keep careful track of your memory locations.



  6. #6
    Member level 2
    Points: 832, Level: 6

    Join Date
    Feb 2013
    Posts
    42
    Helped
    5 / 5
    Points
    832
    Level
    6

    Re: 'Comparison' in assembly language

    89C51 Have the folowing "comparasion"instructions or in other words a "if" something hapens do something

    JZ / JNZ / JC / JNC / JB / JNB / JBC / CJNE

    I "beat"that CJNE is the one that will help you

    The CJNE instruction compares the first two operands and branches to the specified destination if their values are not equal. If the values are the same, execution continues with the next instruction.

    Take a look on this link

    http://www.keil.com/support/man/docs/is51/is51_cjne.htm



  7. #7
    Member level 1
    Points: 540, Level: 4

    Join Date
    Jul 2012
    Posts
    38
    Helped
    0 / 0
    Points
    540
    Level
    4

    Re: 'Comparison' in assembly language

    Quote Originally Posted by ebclr View Post
    89C51 Have the folowing "comparasion"instructions or in other words a "if" something hapens do something

    JZ / JNZ / JC / JNC / JB / JNB / JBC / CJNE

    I "beat"that CJNE is the one that will help you

    The CJNE instruction compares the first two operands and branches to the specified destination if their values are not equal. If the values are the same, execution continues with the next instruction.

    Take a look on this link

    http://www.keil.com/support/man/docs/is51/is51_cjne.htm
    Yes... i have done something like this,

    Code:
            CJNE A,#06H,GREATER      //check if A is greater than 06. If equal then it will fall through
    	LJMP GET_THIRD        // execute "get_third" routine only if it is equal
    GREATER:JNC SEND_SMS        // if they aren't equal then it will check for A>06 (i.e for 0 carry bit) and if C=0 then it will jump to "send_sms" routine 
    	LJMP GET_THIRD  // execute "get_third" routine only if it A<06

    is this correct implementation?



    •   AltAdvertisment

        
       

  8. #8
    Member level 2
    Points: 832, Level: 6

    Join Date
    Feb 2013
    Posts
    42
    Helped
    5 / 5
    Points
    832
    Level
    6

    Re: 'Comparison' in assembly language

    Apear to be, but only you will knew after a simulation and testing . Also note that in todays world normally microprocessor software are implemented in high level languages like C or Pascal, assembler is used only when performance is at premium, othwetrise C will b easyer and will with faster implementation time. The fact is that in 90% of the time a microprocessor is waiting for something to happen



  9. #9
    Member level 1
    Points: 540, Level: 4

    Join Date
    Jul 2012
    Posts
    38
    Helped
    0 / 0
    Points
    540
    Level
    4

    Re: 'Comparison' in assembly language

    Quote Originally Posted by ebclr View Post
    Apear to be, but only you will knew after a simulation and testing . Also note that in todays world normally microprocessor software are implemented in high level languages like C or Pascal, assembler is used only when performance is at premium, othwetrise C will b easyer and will with faster implementation time. The fact is that in 90% of the time a microprocessor is waiting for something to happen
    okay.. :) thank you :)



--[[ ]]--