Re: Question about jumps
- From: "randyhyde@xxxxxxxxxxxxx" <randyhyde@xxxxxxxxxxxxx>
- Date: 30 Aug 2006 14:25:14 -0700
Markus Pitha wrote:
Thanks for the tipps.
As I read in AoA that shifting a byte to the left would multiply the
operand by two, I was in mood to try it out. But unfortunately it didn't
work. I have no clue why, but my following code read a number from stdin,
but doesn't display any output. What's wrong here?
It is amusing how you swear up and down how the AoA/HLA approach isn't
particularly good, and continue to make mistakes that following the
AoA/HLA approach would solve.
Your problem, as others have pointed out, is that you're not to the
point yet where you understand the difference between the string
representation of an integer and the integer itself. Even if you do
understand the difference, you're probably not to the point where you
can write your own integer input and output routines. So instead,
you've written code that reads a *character* from the input, shifts it
to the left, and prints a character to the output. This is a perfect
example of why HLA provides the stdlib and AoA takes advantage of this
early on in the book. Yes, shifting a value to the left one bit
multiplies that value by two. This is something important to learn when
covering the shift instructions. Alas, it's also something you're going
to learn long before you're ready to write your own integer input and
output routines. That's why AoA will have you do something like this:
stdout.put( "Enter an integer:" );
stdin.geti32(); // Read integer from stdin into EAX.
shl( 1, eax ); // Multiply EAX by two
stdout.put( "eax = " );
stdout.puti32( eax );
Now you get to see the effect of the shl instruction without having to
learn all the stuff needed to write your own integer input and output
routines. Sure, at some point you ought to be able to write your own
input and output routines, but for right now the integer I/O routines
in the HLA stdlib are *perfect* for the job. You get to concentrate on
learning about SHL rather than having to make a *long* detour to figure
out numeric I/O (and, having done the detour, you wouldn't need to
learn about SHL at that point anyway).
Yes, there *is* a reason AoA presents the information in the order it
does and there *is* a reason AoA takes advantage of the HLA stdlib.
Cheers,
Randy Hyde
.
- Follow-Ups:
- Re: Question about jumps
- From: Markus Pitha
- Re: Question about jumps
- From: Betov
- Re: Question about jumps
- From: Dragontamer
- Re: Question about jumps
- References:
- Question about jumps
- From: Markus Pitha
- Re: Question about jumps
- From: Evenbit
- Re: Question about jumps
- From: Markus Pitha
- Question about jumps
- Prev by Date: Re: Question about jumps
- Next by Date: Re: PUSH instruction family
- Previous by thread: Re: Question about jumps
- Next by thread: Re: Question about jumps
- Index(es):