【发布时间】:2015-01-11 16:25:26
【问题描述】:
我正在尝试学习如何编写汇编代码,并在 http://gnu.mirrors.pair.com/savannah/savannah//pgubook/ProgrammingGroundUp-0-8.pdf 的帮助下完成。这是一个很好的资源,我正在尝试以 Macho64 格式为我的 Mac 编写 64 位代码。
我在绝对和相对寻址方面遇到了一些麻烦。
这是我的代码:
DEFAULT REL
;PURPOSE: This program finds the maximum number of a set of data items
;
;VARIABLES: The registers have the following uses
;
; rbx - Holds the index of the data item being examined
; rdi - Largest data item found
; rax - Current data item
;
; The following memory locations are used:
;
; data_items - contains the item data. A 0 is used to terminate the data
;
global _main
section .data
data_items: dw 3,67,34,222,45,75,54,34,44,33,22,11,66,0
;These are the data items
section .text
_main:
mov rdi, 0 ;move 0 into index register
mov rax, [data_items+rbx*4] ;load the first data byte
mov rdi, rax ;since this is the first item, eax is biggest
start_loop: ;start loop
cmp 0, rax ;check to see if we've hit the end
je loop_exit
inc rdi
mov rax, [data_items+rbx*4]
cmp rdi, rax
jle start_loop
mov rdi,rax
jmp start_loop
loop_exit:
mov rax, 0x2000001 ;1 is the exit() syscall
syscall
这些是我收到的错误消息:
Samuels-MBP:Starting sam$ make
src/maximum.s:26: error: Mach-O 64-bit format does not support 32-bit absolute addresses
src/maximum.s:30: error: invalid combination of opcode and operands
src/maximum.s:33: error: Mach-O 64-bit format does not support 32-bit absolute addresses
所以我想知道是否有人可以帮助我。我查找了相对寻址,但找不到任何用简单语言解释我做错了什么的东西。
我也知道 cmp 语句是错误的,但我想我可以自己解决这个问题。
【问题讨论】:
-
相关:Mach-O 64-bit format does not support 32-bit absolute addresses. NASM Accessing Array,看起来这个问题是另一个尝试将 PGU 示例代码从 32 位 Linux 移植到 64 位 OS X。(当您刚刚学习时,这不是一件容易的事首先是asm!)
标签: macos assembly nasm x86-64