I've finally decided to take the plunge and learn assembly language, something I've always been interested in doing. I have a few books on Computer Architecture because I realize I need an understanding of that as well. I'm trying to convert the second program example of 'Programming from the ground up' and I've narrowed the mistakes down to just two lines and I cant get any further. The docs for nasm itself are'nt much help at the moment. I use amd64 with slackware 13. Can anyone help with code and explanations please, thank you. David.
Here is the original code
; eax - current data item
; ebx - largest data item found
; edi - holds the index of the data item being examined
.section .data
data_items:
.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0
.section text
.globl _start
_start:
movl $0, %edi
movl data_items(,%edi,4), %eax
movl %eax, %ebx
start_loop:
cmpl $0, %eax
je loop_exit
incl %edi
movl data_items(,%edi,4), %eax
cmpl %ebx, %eax
jle start_loop
movl %eax, %ebx
jmp start_loop
loop_exit:
movl $1, %eax
int $0x80
Ok here is my code converted to nasm as best I can. My trouble is
with indexed addressing, I've tried numerous variations but nothing
works.
;maximum.asm
;this program finds the maximum number of a set of data items
;
;VARIABLES: the registers have the following uses:
;
; rax: current data item
; rbx: largest data item found
; rdi: holds the index of the data item being examined
;
;the following memory locations are used
;
; data_items: contains the item data. 0 is used to terminate the data
section .text
global _start
_start:
mov rdi,0
mov rax,data_items,[rdi+4]
mov rbx,rax
start_loop:
cmp rax,0
je loop_exit
inc rdi
mov rax,data_items,[rdi+4]
cmp rax,rbx
jle start_loop
mov rbx,rax
jmp start_loop
loop_exit:
mov rax,1
int 0x80
section .data
data_items:
db 3,64,23,56,78,44,87,35,54,0
Looking forward to all replies and advice, thanks.