The logic behind some code

Discussion in 'Assembly Language Programming (ALP) Forum' started by Shafqat, Nov 30, 2008.

  1. Shafqat

    Shafqat New Member

    Joined:
    Nov 27, 2008
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    I'm looking at a subroutine and trying to figure out the logic behind it. (coldfire processor)

    It's supposed to accept an input character from a user and then call on another subroutine to print it to the console.

    The character is saved to the lower byte of a certain register D.

    However before D is sent to the subroutine that prints it, it is first logic anded with 7F. I dont understand why though? :)

    Thanks
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Perhaps the subroutine does something odd if bit 7 is 1. You'd need to look at the subroutine (specifically what it does when bit 7=1) to determine why it's necessary to and it with 7f.
     
  3. Shafqat

    Shafqat New Member

    Joined:
    Nov 27, 2008
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    So I found out that D is first logic anded with 7F in order to obtain only the first byte of it and use it in the other subroutines

    But I don't see how anding it with 7F give you the first byte... doesnt it give you the first byte short of 1 since 7F = 0111 1111 ?

    Thanks
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    You're correct, that doesn't make sense. Anding it with 7f resets bit 7. It may be that register D may contain some unwanted data in bits 8+ and ANDing it with ff would clear all those bits.

    So perhaps the AND 7F (a) gives you just the first byte *and* (b) resets bit 7 for some other reason.
     
  5. Shafqat

    Shafqat New Member

    Joined:
    Nov 27, 2008
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Thanks, I think I get it now. :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice