2016-10-09 2 views
-2

Ich habe diesen einfachen Code in JavaScript geschrieben und verwende d8, um den Assemblercode anzuzeigen. Jetzt möchte ich diesen Assemblycode ausführen, aber ich kann das nicht machen.Wie führe ich diesen Assemblercode aus?

Hier ist mein Code

print('Hello') 

Und das ist die Montage I Suche von d8

--- Raw source --- 
print('Hello'); 


--- Code --- 
source_position = 0 
kind = FUNCTION 
compiler = full-codegen 
Instructions (size = 180) 
0x13fb4a04740  0 55    push rbp 
0x13fb4a04741  1 4889e5   REX.W movq rbp,rsp 
0x13fb4a04744  4 56    push rsi 
0x13fb4a04745  5 57    push rdi 
0x13fb4a04746  6 488b4f2f  REX.W movq rcx,[rdi+0x2f] 
0x13fb4a0474a 10 488b490f  REX.W movq rcx,[rcx+0xf] 
0x13fb4a0474e 14 83411b01  addl [rcx+0x1b],0x1 
0x13fb4a04752 18 41ff75a0  push [r13-0x60] 
0x13fb4a04756 22 493ba5200c0000 REX.W cmpq rsp,[r13+0xc20] 
0x13fb4a0475d 29 7305   jnc 36 (0x13fb4a04764) 
0x13fb4a0475f 31 e8dce2f4ff  call StackCheck (0x13fb4952a40) ;; code: BUILTIN 
0x13fb4a04764 36 48b80000000004000000 REX.W movq rax,0x400000000 
0x13fb4a0476e 46 e86dfcffff  call 0x13fb4a043e0  ;; code: LOAD_GLOBAL_IC 
0x13fb4a04773 51 50    push rax 
0x13fb4a04774 52 49ba1123f8ee15360000 REX.W movq r10,0x3615eef82311 ;; object: 0x3615eef82311 <undefined> 
0x13fb4a0477e 62 4152   push r10 
0x13fb4a04780 64 49ba19b92ab6eb2a0000 REX.W movq r10,0x2aebb62ab919 ;; object: 0x2aebb62ab919 <String[5]: Hello> 
0x13fb4a0478a 74 4152   push r10 
0x13fb4a0478c 76 48ba0000000002000000 REX.W movq rdx,0x200000000 
0x13fb4a04796 86 488b7c2410  REX.W movq rdi,[rsp+0x10] 
0x13fb4a0479b 91 e820ffffff  call 0x13fb4a046c0  ;; code: CALL_IC 
0x13fb4a047a0 96 488b75f8  REX.W movq rsi,[rbp-0x8] 
0x13fb4a047a4 100 4883c408  REX.W addq rsp,0x8 
0x13fb4a047a8 104 488945e8  REX.W movq [rbp-0x18],rax 
0x13fb4a047ac 108 488b45e8  REX.W movq rax,[rbp-0x18] 
0x13fb4a047b0 112 48bbd1ba2ab6eb2a0000 REX.W movq rbx,0x2aebb62abad1 ;; object: 0x2aebb62abad1 Cell for 6144 
0x13fb4a047ba 122 83430bd1  addl [rbx+0xb],0xd1 
0x13fb4a047be 126 791f   jns 159 (0x13fb4a047df) 
0x13fb4a047c0 128 50    push rax 
0x13fb4a047c1 129 e8fae1f4ff  call InterruptCheck (0x13fb49529c0) ;; code: BUILTIN 
0x13fb4a047c6 134 58    pop rax 
0x13fb4a047c7 135 48bbd1ba2ab6eb2a0000 REX.W movq rbx,0x2aebb62abad1 ;; object: 0x2aebb62abad1 Cell for 6144 
0x13fb4a047d1 145 49ba0000000000180000 REX.W movq r10,0x180000000000 
0x13fb4a047db 155 4c895307  REX.W movq [rbx+0x7],r10 
0x13fb4a047df 159 c9    leavel 
0x13fb4a047e0 160 c20800   ret 0x8 
0x13fb4a047e3 163 498b45a0  REX.W movq rax,[r13-0x60] 
0x13fb4a047e7 167 e9c4ffffff  jmp 112 (0x13fb4a047b0) 
0x13fb4a047ec 172 0f1f4000  nop 

Nun möchte ich, dass die Assembler-Code ausführen möchte ich diesen Fehler:

cc -s print.s
print.s:1:1: error: 32-bit absolute addressing is not supported in 64-bit mode

Dies ist mein print.s

push rbp 
movq rbp,rsp 
push rsi 
push rdi 
movq rcx,[rdi+0x2f] 
movq rcx,[rcx+0xf] 
addl [rcx+0x1b],0x1 
push [r13-0x60] 
cmpq rsp,[r13+0xc20] 
jnc 36 
call StackCheck 
movq rax,0x400000000 
call 0x13fb4a043e0 
push rax 
movq r10,0x3615eef82311 
push r10 
movq r10,0x2aebb62ab919 
push r10 
movq rdx,0x200000000 
movq rdi,[rsp+0x10] 
call 0x13fb4a046c0 
movq rsi,[rbp-0x8] 
addq rsp,0x8 
movq [rbp-0x18],rax 
movq rax,[rbp-0x18] 
movq rbx,0x2aebb62abad1 
addl [rbx+0xb],0xd1 
jns 159 
push rax 
call InterruptCheck 
pop rax 
movq rbx,0x2aebb62abad1 
movq r10,0x180000000000 
movq [rbx+0x7],r10 
leavel 
ret 0x8 
movq rax,[r13-0x60] 
jmp 112 
nop 
+0

Wie ist das Off-Topic? – toy

+0

Sie sind auf OS X, oder? Andere Betriebssysteme erlauben absolute Adressen. –

+1

Ich stimme ab, diese Frage als off-topic zu schließen, weil sie auf solch einer falschen Voraussetzung basiert, dass es keine sinnvolle Antwort gibt, außer "Sie können ein asm-Fragment nicht aus einem Javascript-JIT nehmen und es als eigenständiges Programm ausführen ". Vor allem nicht, wenn etwas gedruckt wird, anstatt nur eine Eingabe von einer Ausgabe zu berechnen. –

Antwort

1

Sie können kein Snippet aus einem Programm mit festen Zeigern machen, kopieren und einfügen und erwarten, dass es funktioniert.

Ihr Snippet wird nie funktionieren.
Es referenziert absolute Adressen, die nur im Kontext des ursprünglichen Programms, in dem es ausgeführt wurde, gültig sind.
Das nächste Mal das ursprüngliche Programm ausgeführt wird die Adressen wahrscheinlich aufgrund ASLR, ganz neben der Tatsache, dass alle Programme in OSX muss verlagerbar sein; d. h. feste Adressen existieren nicht in OSX.
In jedem Fall zeigen Sie auf Laufzeitcode, der in Ihrem Copy-Paste-Snippet einfach nicht vorhanden ist.

Sie müssen lernen, wie man ein eigenständiges "Hallo Welt" -Aufbauprogramm schreibt.

Es gibt 100 von Tutorials beschreiben, wie dies zu tun, z.B .: http://peter.michaux.ca/articles/assembly-hello-world-for-os-x

hello.asm - a "hello, world" program using NASM 

section .text 

global mystart    ; make the main function externally visible 

mystart: 

; 1 print "hello, world" 

    ; 1a prepare the arguments for the system call to write 
    push dword mylen   ; message length       
    push dword mymsg   ; message to write 
    push dword 1    ; file descriptor value 

    ; 1b make the system call to write 
    mov eax, 0x4    ; system call number for write 
    sub esp, 4    ; OS X (and BSD) system calls needs "extra space" on stack 
    int 0x80     ; make the actual system call 

    ; 1c clean up the stack 
    add esp, 16    ; 3 args * 4 bytes/arg + 4 bytes extra space = 16 bytes 

; 2 exit the program 

    ; 2a prepare the argument for the sys call to exit 
    push dword 0    ; exit status returned to the operating system 

    ; 2b make the call to sys call to exit 
    mov eax, 0x1    ; system call number for exit 
    sub esp, 4    ; OS X (and BSD) system calls needs "extra space" on stack 
    int 0x80     ; make the system call 

    ; 2c no need to clean up the stack because no code here would executed: already exited 

section .data 

    mymsg db "hello, world", 0xa ; string with a carriage-return 
    mylen equ $-mymsg    ; string length in bytes 

Wenn Sie Assembler-Code schreiben wollen unter OSX laufen Sie auch how the OSX API works lernen müssen.