dave343
[H]ard|Gawd
- Joined
- Oct 17, 2000
- Messages
- 1,869
Hey all,
I recently decided I wanted to take up some programming, and have started with Linux Assembly so that's what I'm trying to teach myself. The quick answer to why is that I've been a PC Technician for years and what to change IT careers, and I have a big interest in programming. I decided to start with Assembly as I wanted to start at the bottom to understand things more, and the linux part is because that's the book I'm working through.
But, I've run into a problem that I did manage to solve (pat on back)... but I can't fully wrap my head around the solution, so hopefully someone can explain it a bit for me.
There was a program to find a maximum number, and then the author explains in detail what every step does after. At the end of the chapter, the Author has some review questions, and asks that you make the program now find the minimum.
Ok... so after a few hours (yes it took me that long) I finally figured out I needed to change a JLE (jump if the second value is less than the first), to JG (jump if the second value is greater than the first).
GREAT, so after change this value, now it finds the minimum number. But wait... since the numbers are not in lowest to highest, or highest to lowest... to me, that means the jump won't always be true. Because once the EAX register (see below) has a higher or lower number then before, and different to what is in EBX, how is it still finding the lowest?
See the code below. Hopefully someone can help explain to me how this program finds the lowest value when changing JLE to JG. I had to break down each line of the code to fully understand what was going on so I knew which line I needed to change. But it's just trying to understand my own resolution, that jump (JE) "Jump if second value is greater than the first". Since the numbers are not in order, to me the jump statement wouldn't always be true, and yet it still runs through all the numbers until it finds the correct mimimum number. Thanks in advance.
.section .data
data_items:
.long 67,34,222,45,75,54,34,44,33,22,11,66,255
.section .text
.globl _start
_start:
movl $0, %edi
movl data_items(,%edi,4), %eax
movl %eax, %ebx
start_loop:
cmpl $255, %eax
je loop_exit
incl %edi
movl data_items(,%edi,4), %eax
cmpl %ebx, %eax
jl start_loop
movl %eax, %ebx
jmp start_loop
loop_exit:
movl $1, %eax
int $0x80
I recently decided I wanted to take up some programming, and have started with Linux Assembly so that's what I'm trying to teach myself. The quick answer to why is that I've been a PC Technician for years and what to change IT careers, and I have a big interest in programming. I decided to start with Assembly as I wanted to start at the bottom to understand things more, and the linux part is because that's the book I'm working through.
But, I've run into a problem that I did manage to solve (pat on back)... but I can't fully wrap my head around the solution, so hopefully someone can explain it a bit for me.
There was a program to find a maximum number, and then the author explains in detail what every step does after. At the end of the chapter, the Author has some review questions, and asks that you make the program now find the minimum.
Ok... so after a few hours (yes it took me that long) I finally figured out I needed to change a JLE (jump if the second value is less than the first), to JG (jump if the second value is greater than the first).
GREAT, so after change this value, now it finds the minimum number. But wait... since the numbers are not in lowest to highest, or highest to lowest... to me, that means the jump won't always be true. Because once the EAX register (see below) has a higher or lower number then before, and different to what is in EBX, how is it still finding the lowest?
See the code below. Hopefully someone can help explain to me how this program finds the lowest value when changing JLE to JG. I had to break down each line of the code to fully understand what was going on so I knew which line I needed to change. But it's just trying to understand my own resolution, that jump (JE) "Jump if second value is greater than the first". Since the numbers are not in order, to me the jump statement wouldn't always be true, and yet it still runs through all the numbers until it finds the correct mimimum number. Thanks in advance.
.section .data
data_items:
.long 67,34,222,45,75,54,34,44,33,22,11,66,255
.section .text
.globl _start
_start:
movl $0, %edi
movl data_items(,%edi,4), %eax
movl %eax, %ebx
start_loop:
cmpl $255, %eax
je loop_exit
incl %edi
movl data_items(,%edi,4), %eax
cmpl %ebx, %eax
jl start_loop
movl %eax, %ebx
jmp start_loop
loop_exit:
movl $1, %eax
int $0x80
Last edited: