Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   The logic behind some code (http://www.go4expert.com/forums/logic-code-t15307/)

Shafqat 30Nov2008 17:56

The logic behind some code

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? :)


xpi0t0s 30Nov2008 18:01

Re: The logic behind some code
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.

Shafqat 3Dec2008 16:53

Re: The logic behind some code

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 ?


xpi0t0s 3Dec2008 17:06

Re: The logic behind some code
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.

Shafqat 3Dec2008 17:19

Re: The logic behind some code
Thanks, I think I get it now. :D

All times are GMT +5.5. The time now is 04:05.