|
From: | Burak Can KUŞ |
Subject: | [Pgubook-readers] Programming from the Ground Up / Programming Under the Hood / Chapter 3 Review |
Date: | Sun, 22 May 2016 20:21:33 +0000 |
Hello everyone,
I have seen here "http://programminggroundup.blogspot.com.tr/2007/01/appendix-g-document-history.html" that this book has a V1.1 but I can't seem to find it's pdf anywhere. Where can I find it? I know that there is a plan on releasing "Programming Under the Hood" but I was just wondering since the change-log said that there were lots of minor updates on the book. Also I try to answer all the review questions as good as I can but as someone else pointed some years ago, is there any way to compare our answers to solutions of these reviews? Are you also planning to put solutions or something similar to the new book? I'm also kind of confused about the 3rd chapter reviews. To solve this question "Modify the maximum program to use an ending address rather than the number 0 to know when to stop." my instinct was to get the address of the last item in data_items and compare that address with the address we're checking each time. I kind of implemented it like this; (But my question is, should I calculate the byte offset of the last item every time by hand? I tried things like data_items(,15,8) but I knew that memory address reference doesn't work like this. And lastly, lets say there is an X variable, I want to get the address of X and add Y to it and store it in a register. How can I do that without using lea instruction? Can I do that using mov instruction? .section .data data_items: #These are the data items .quad 3,67,2,34,222,45,75,54,34,44,33,1,22,11,66,245 .section .text .globl _start _start: movq $0, %rdi # move 0 into the index register lea data_items + 120, %rdx # put the address of the 15th (15 * 8 = 120 since it is the last item) item to rdx movq data_items(,%rdi,8), %rax # load the first byte of data movq %rax, %rbx # since this is the first item, %rax is # the smallest start_loop: # start loop lea data_items(,%rdi,8), %r10 # put the address of the item being examined to r10 cmpq %rdx, %r10 # check to see if we've hit the end je loop_exit incq %rdi # load next value movq data_items(,%rdi,8), %rax cmpq %rbx, %rax # compare values jle start_loop # jump to loop beginning if the new # one isn't bigger movq %rax, %rbx # move the value as the smallest jmp start_loop # jump to loop beginning loop_exit: # %rbx is the status code for the exit system call # and it already has the minimum number movq $1, %rax #1 is the exit() syscall Thanks in advance, |
[Prev in Thread] | Current Thread | [Next in Thread] |