The logic behind some code

Go4Expert Member
30Nov2008,17:56   #1
Shafqat's Avatar
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
Mentor
30Nov2008,18:01   #2
xpi0t0s's Avatar
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.
Go4Expert Member
3Dec2008,16:53   #3
Shafqat's Avatar
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
Mentor
3Dec2008,17:06   #4
xpi0t0s's Avatar
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.
Go4Expert Member
3Dec2008,17:19   #5
Shafqat's Avatar
Thanks, I think I get it now.