所以我接受了汇编编程。在我的Ubuntu盒子上非常简单:使用NASMamd GNU ld,我能够在半小时内编写或多或少复杂的HelloWorld风格的程序。 但是当谈到iPhone时,它是如此复杂。首先,我在4.2.1固件上有一个JB'en iPhone 3G,这意味着我使用了Darwin内核v10的ARM端口。 第二。我必须使用GNU,因为没有适用于iPhone的NASM:本机工具链(Mac OS X上的Xcode和Linux上的opensource tooolchain)使用GCC。 所以我收集了以下基本信息: - 如何在GNU中编写汇编语言; - 什么是基本的ARM指令,寄存器,内存访问。
但即使HelloWorld也需要内核调用来写入stdout。我的问题是:使用什么内核调用以及如何(什么参数去哪里);我应该使用swi #ARM指令,不应该吗?
那么,您能否发布一些教程信息/链接,或者发布ARM Darwin Hello world asm代码的人?
截至目前,我可以这样做:
;Hello World for Linux and NASM
section data
hello db "Hello World"
helloLen equ $ - hello
section text
global _start
_start:
mov eax, 4 ; sys_write
mov ebx, 1 ; to stdout
mov ecx, hello ; address of string
mov edx, helloLen ; value (because of eq!!!) of strLen
int 0x80 ; call awesome Linux kernel
mov eax, 1 ; sys_exit
mov ebx, 0 ; "return 0; " if you like C
int 0x80 ; call kernel to end program
但是,对于ARM,我只能这样做:
.text
start:
mov r0, #0
mov r1, #234
add r2, r0, r1
@all mov and add and other stuff works fine
swi #0xc00
@all that I get is Bad system call error
那么,有人请吗?
答案 0 :(得分:1)
以下是libc(libSystem)的用法:
; ssize_t read(int, void *, size_t)
EXPORT _read
_read
MOV R12, #3 ; SYS_read
SVC 0x80 ; 'А' ; do a syscall
BCC _ok ; carry clear = no error
LDR R12, =(cerror_ptr - . - 8) ; otherwise call error handler
LDR R12, [PC,R12] ; load pointer
B _call_error
DCD cerror_ptr - .
_call_error
BX R12 ; cerror ; jump to it (error number is in R0)
_ok
BX LR ; return to caller
; End of function _read
即:
答案 1 :(得分:1)
最好的我能快速找到,是的,我知道最初的帖子是旧的
http://blog.softboysxp.com/post/7888230192/a-minimal-168-byte-mach-o-arm-executable-for-ios
.text
.globl start
start:
mov r2, #14
adr r1, hello_str
mov r0, #1
mov r12, #4
swi 0x80
mov r0, #0
mov r12, #1
swi 0x80
hello_str:
.ascii "Hello, World!\n"
compile:
as new.asm -o new.o
ld new.o -o new
./new