Last active
August 29, 2015 13:56
-
-
Save clzola/8972691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Kompajliranje | |
nasm -f elf -o <ime.o> <datoteka.asm> | |
# Dobili smo object datoteku (.o) | |
# Sada linkujemo | |
ld -s -o <ime> <datoteka.o> | |
# Izvrsavanje | |
./<ime> | |
# Sa C funkcijama | |
gcc -o <ime> <datoteka.o> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
int ret_value; | |
ret_value = asm_main(); | |
return ret_value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern printf | |
global main | |
section .data | |
msg db 'Ovo je poruka iz asemblera',10,0 | |
section .bss | |
section .text | |
main: | |
; priprema steka | |
push ebp | |
mov ebp, esp | |
push msg | |
call printf | |
; kraj | |
mov esp, ebp | |
pop ebp | |
ret | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Program koji ne radi nista | |
; C Ekvivalent: | |
; void main(){} | |
; Potrebno je samo pravilno izaci iz programa | |
; sa EXIT_SUCCESS (=0) | |
; Ovo ce raditi | |
; Ali nije korektno xD | |
; Moramo da napisemo kod koji ce da pripremi | |
; proces za ispravan rad | |
global _start ; Ovo je kao main | |
section .text | |
_start: | |
mov ebx, 0 ;Definisanje | |
mov eax, 1 ;Exit sistemskog poziva | |
int 0x80 ;Izvrsavanje interupta (syscall) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global _start | |
; Ispravno je da se prvo sacuvaju pokazivaci steka | |
section .text | |
_start: | |
; Priprema | |
push ebp ; Cuvanje pokazivaca osnove steka | |
move ebp, esp ; Base pokazivac i stack pointer u base pointer | |
; Neki kod programa | |
; ... | |
; Izlazak iz programa | |
move esp, ebp ; Prethodni segment steka | |
pop ebp ; Prethodna baza steka | |
mov ebx, 0 ; Definisanje | |
mov eax, 1 ; exit sistemskog poziva | |
int 0x80 ; Izvrsavanje interapta (syscall) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global _start | |
; Unose se dva znaka | |
; Stampamo ta dva znaka | |
; Nije preporucljivo preko toliko interapta | |
section .data | |
poruka1 db 'Unesite dva proizvoljna znaka',10,0 | |
poruka2 db 'Vrijednosti koje ste unijeli su: ',0 | |
poruka1_len equ $-poruka1 | |
poruka2_len equ $-poruka2 | |
novi_red db 10 | |
section .bss | |
ulazni_podaci resb 2 | |
section .text | |
_start: | |
; Priprema steka | |
push ebp | |
mov ebp, esp | |
; Ispisivanje poruke na konzoli | |
; Koristimo sistemski poziv write() | |
mov eax, 0x4 ; id syscall for write | |
mov ebx, 1 ; fd | |
mov ecx, poruka1 ; adresa buffer-a | |
mov edx, poruka1_len ; velicina bufera | |
int 0x80 ; Izvrsavanje interapta | |
; Unosenje sa tastature | |
; Korismo sistemski poziv read() | |
mov eax, 0x3 ; id syscall for read | |
mov ebx, 0 ; fd | |
mov ecx, ulazni_podaci ; adresa buffer-a | |
mov edx, 2 ; velicina | |
int 0x80 | |
; Ispisivanje izlazne poruke | |
mov eax, 0x4 ; id syscall for write | |
mov ebx, 1 ; fd | |
mov ecx, poruka2 ; adresa buffer-a | |
mov edx, poruka2_len ; velicina bufera | |
int 0x80 ; Izvrsavanje interapta | |
; Ispisivanje izlaznih podataka | |
mov eax, 0x4 ; id syscall for write | |
mov ebx, 1 ; fd | |
mov ecx, ulazni_podaci ; adresa buffer-a | |
mov edx, 2 ; velicina bufera | |
int 0x80 ; Izvrsavanje interapta | |
; Ispisivanje novog reda | |
mov eax, 0x4 ; id syscall for write | |
mov ebx, 1 ; fd | |
mov ecx, novi_red ; adresa buffer-a | |
mov edx, 1 ; velicina buffer-a | |
int 0x80 ; poziv interapta | |
; Pravilan izlazak iz programa | |
mov esp, ebp | |
pop ebp | |
mov ebx, 0 | |
mov eax, 1 | |
int 0x80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern printf ; ubacanje priintf, nesto kao include <stdio.h> | |
global main | |
section .data | |
msg db 'Poruka iz asemblera',10,0 | |
section .text | |
main: | |
; Priprema steka | |
push ebp | |
mov ebp, esp | |
push msg ; poruka se gura na stek jer printf trazi da se poruka nalazi | |
; na steku | |
call printf ; poziv printf C funkcije | |
; kraj | |
mov esp, ebp | |
pop ebp | |
ret ; sa exit, umjesto sistemskog poziva nestko kao makro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%include "asm_io.inc" | |
; nasm -f elf -o driver.o driver.asm | |
; gcc -o <ime programa> driver.o PRG06.o asm_io.o | |
; redosled nema veze | |
; asm_io.o je dodatak koji treba da se skine | |
segment .data | |
segment. bss | |
segment .text | |
global asm_main | |
asm_main: | |
enter 0,0 ; setup routine | |
pusha | |
popa | |
mov eax, 0 ; return back to C | |
leave | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment