Erinevus lehekülje "Assembler" redaktsioonide vahel

Allikas: Kuutõrvaja
(?)
(Kompileerimine)
 
(ei näidata sama kasutaja 7 vahepealset redaktsiooni)
20. rida: 20. rida:
 
== Hello World ==
 
== Hello World ==
  
  global _start
+
<source lang="asm">
 +
global _start
 
    
 
    
  section .data
+
section .data
          hello  db      "Hello, World!", 10
+
        hello  db      "Hello, World!", 10
          length  equ    $-hello
+
        length  equ    $-hello
 
    
 
    
  section .text
+
section .text
 
    
 
    
  _start:
+
_start:
          mov eax, 4      ; write to file
+
        mov eax, 4      ; write to file
          mov ebx, 1      ; STDOUT handle
+
        mov ebx, 1      ; STDOUT handle
          mov ecx, hello  ; our message
+
        mov ecx, hello  ; our message
          mov edx, length ; size of message
+
        mov edx, length ; size of message
          int 80h        ; execute the syscall
+
        int 80h        ; execute the syscall
 +
 +
        xor ebx, ebx    ; send 0 as 'exit code'
 +
        mov eax, 1      ; terminate process
 +
        int 80h        ; execute the syscall
 +
</source>
  
          xor ebx, ebx    ; send 0 as 'exit code'
+
= Kompileerimine =
          mov eax, 1      ; terminate process
+
 
          int 80h        ; execute the syscall
+
Oletame, et soovime kompileerida programmi '''helloworld''', mille assembleri kood on failis '''helloworld.asm'''.
 +
 
 +
Linuxile saab kompileerimiseks sikutada programmi nimega '''nasm'''.
 +
 
 +
<source lang="bash">
 +
nasm -f elf helloworld.asm
 +
</source>
 +
 
 +
Käsu kävivitamisel genereetitakse meile fail nimega '''helloworld.o'''.
 +
 
 +
<source lang="bash">
 +
ld -o helloworld helloworld.o
 +
</source>
 +
 
 +
Käsu kävitamisel genereeritakse meile käivitatav programm nimega '''helloworld'''. Programmi käivitatakse nagu teisigi programme:
 +
 
 +
<source lang="bash">
 +
./helloworld
 +
</source>
  
 
= Lingid =
 
= Lingid =

Viimane redaktsioon: 20. juuni 2011, kell 12:38

TODO

Näited

???

assembler; label l1, l2;

asm
 mov dx,3DAh
 l1:
  in al, dx
  and al,08h
  jnz l1
 l2:
  in al,dx
  and al,08h
  jz l2

Hello World

global _start
  
section .data
        hello   db      "Hello, World!", 10
        length  equ     $-hello
  
section .text
  
_start:
        mov eax, 4      ; write to file
        mov ebx, 1      ; STDOUT handle
        mov ecx, hello  ; our message
        mov edx, length ; size of message
        int 80h         ; execute the syscall
 
        xor ebx, ebx    ; send 0 as 'exit code'
        mov eax, 1      ; terminate process
        int 80h         ; execute the syscall

Kompileerimine

Oletame, et soovime kompileerida programmi helloworld, mille assembleri kood on failis helloworld.asm.

Linuxile saab kompileerimiseks sikutada programmi nimega nasm.

nasm -f elf helloworld.asm

Käsu kävivitamisel genereetitakse meile fail nimega helloworld.o.

ld -o helloworld helloworld.o

Käsu kävitamisel genereeritakse meile käivitatav programm nimega helloworld. Programmi käivitatakse nagu teisigi programme:

./helloworld

Lingid

http://www.csn.ul.ie/~darkstar/assembler/

http://www.csn.ul.ie/~darkstar/assembler/intlist.html