[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pgubook-readers] Introduction and question
From: |
Pupeno |
Subject: |
[Pgubook-readers] Introduction and question |
Date: |
Fri, 3 Dec 2004 22:42:49 -0300 |
User-agent: |
KMail/1.7.1 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello readers,
I have just found out about this book, Programming from the Ground Up
obviusly, and I have download it and I'm reading it and learning a lot.
I'd like to start by thanking Jonathan Bartlett for writting what so far (page
41) is an excelent book and offering it for free. Putting it in a place like
savannah, making a mailing list and so on was a great idea. It makes me not
feel alone in the process of readint it and learning. Thank you a lot
Jonathan Bartlett!!!!!!
Now, the question. I have just read the full explanation of maximum.s, a
program that looks for the maximum number in a list of numbers... the second
program in the book.
The first thing I didn't like was the pre-fetch of a value. That is, it
fetches a value from the list, puts it into a register an then the loops
starts. And obviusly, during the loops, more values are fetched (with exactly
the same sentence). The fact is that I've been programming for more than 10
years already and I never liked that kind of things: sentences that are
repeated, inside and outside of a loop. Is there any good reason to have done
it that way ? I proposed myself re-work it to make it the way I like it and
it is even shorter and I think, maybe easier to understand (the resulting
source is at the end). Maybe, I'm just missing something, or was it just
pedagojical or just because, I don't know.
Anyway, thanks again to Jonathan Bartlett!!!!
- --
Pupeno: address@hidden - http://www.pupeno.com
PS: I've filled some 'support request' at the savannah tracker. They are more
like bug reports... anyway, will they be ever noticed ?
PSPS: The source code:
.section .data
data_items:
.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0
.section .text
.globl _start
_start:
# Put 0 in %edi, the index register.
movl $0, %edi
# Put 0 in %ebx, the largest item so far (this will limit us to work with
numbers greater than 0, but we are already limited to that).
movl $0, %ebx
start_loop:
# Put the next number into %eax.
movl data_items(,%edi,4), %eax
# Compare the just-fetched number, %eax, to 0.
cmpl $0, %eax
# If it is 0, jump to loop_exit, finish the program.
je loop_exit
# Increment the index for the next interation.
incl %edi
# Compare the current biggest number, %ebx, to the new number, %eax.
cmpl %ebx, %eax
# If the newest number, %eax, is lower or equal, continue fetching numbers.
jle start_loop
# If not, store a new biggest number...
movl %eax, %ebx
# And continuew looping.
jmp start_loop
loop_exit:
movl $1, %eax
int $0x80
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
iD8DBQFBsRYbfW48a9PWGkURAogfAJ0VrCElN3mgHzgMMfQ2VN4NYLkFAACdGT8C
/YHa76tYipzL6db1pr+hvv8=
=KyKB
-----END PGP SIGNATURE-----
- [Pgubook-readers] Introduction and question,
Pupeno <=