The logic behind some code

Shafqat's Avatar
Go4Expert 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
0
xpi0t0s's Avatar, Join Date: Aug 2004
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.
0
Shafqat's Avatar
Go4Expert 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
0
xpi0t0s's Avatar, Join Date: Aug 2004
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.
0
Shafqat's Avatar
Go4Expert Member
Thanks, I think I get it now.