1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

The logic behind some code

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

  1. Shafqat

    Shafqat New Member

    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

    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

    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

    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

    Thanks, I think I get it now. :D
     

Share This Page