Assembly Interpreter:

1. Assembly Interpreter:

???
gokernel

(usa Linux Mint)

Enviado em 02/01/2014 - 11:51h


Olá !!!

No dia de ano, enquanto esperava a PIZZA em +ou- 35 minutos fiz algo em pulo Assembly para passar o tempo:



;--------------------------------------------------------------------
;
; A simple example using only SDL.
;
; USAGE:
; asmi test.asm
;
; BY: gokernel - gokernel@hotmail.com
;
;--------------------------------------------------------------------

library SDL ; in windows: SDL.dll
library libSDL ; in linux: libSDL.so

import SDL_Init
import SDL_SetVideoMode
import SDL_FillRect
import SDL_Flip
import SDL_PollEvent
import SDL_Delay
import SDL_Quit

long i
char *ev
char *screen
char *r ; SDL_Rect: short(x,y,w,h) sizeof 8

.S_count "mouse pos: %d %d\n"

;// <<<<< START >>>>>
push %ebp ;// index: 0
mov %esp,%ebp
sub $16,%esp ;// set to 4 arguments

movl $100,(%esp) ;// ev = malloc(100);
call malloc
mov %eax,ev

movl $8,(%esp) ;// r = malloc(8);
call malloc
mov %eax,r

mov r,%eax ; // r->x = 100 ...
movw $100,(%eax) ; short
movw $100,2(%eax)
movw $100,4(%eax)
movw $100,6(%eax)

movl $32,(%esp)
call SDL_Init

movl $0,12(%esp)
movl $32,8(%esp)
movl $600,4(%esp)
movl $800,(%esp)
call SDL_SetVideoMode
mov %eax,screen

movl $16744990,8(%esp) ;// color orange
mov r,%eax
mov %eax,4(%esp)
mov screen,%eax
mov %eax,(%esp)
call SDL_FillRect ;// SDL_FillRect (screen, r, 16744990);

mov screen,%eax
mov %eax,(%esp)
call SDL_Flip

label_top: ;//<<<<<<< main loop >>>>>>>

mov ev,%eax ;// if (SDL_PollEvent(ev)) {
mov %eax,(%esp)
call SDL_PollEvent
test %eax,%eax
je label_ok_event
;------------------- {

mov ev,%eax ; // printf("mouse pos: %d %d\n", ev->x, ev->y );
movzwl 6(%eax),%edx
mov %edx,8(%esp) ; // ev->y
;;;;; mov ev,%eax ; // NOT NEED: %eax not changed
movzwl 4(%eax),%eax
mov %eax,4(%esp) ; // ev->x
mov S_count,%eax
mov %eax,(%esp) // S_count: "mouse pos: %d %d\n"
call printf

; //** test event: SDL_KEYUP = 3
mov ev,%eax
cmpb $3,(%eax) ;// compare byte: if (ev->type == 3) {
jne label_key
jmp label_end
label_key:

;------------------- }
label_ok_event:
movl $10,(%esp)
call SDL_Delay

jmp label_top ;//<<<<<<< goto the top of main loop >>>>>>>

label_end:
call SDL_Quit
call word
leave
ret

label_fim:




Para quem curte/estuda Assembly o "interpreter" com o codigo encontra-se aqui:

ASMI: Assembly "interpreter"
http://code.google.com/p/microasm/downloads/list

Sério, fazia muito tempo que procurava por uma ferramenta deste tipo para testar programas ...

Espero que alguem goste ...

T+.




  


2. Re: Assembly Interpreter:

???
gokernel

(usa Linux Mint)

Enviado em 02/01/2014 - 11:55h


E LEMBRANDO:

E para sair do loop tecle qualquer tecla...




3. Re: Assembly Interpreter:

???
gokernel

(usa Linux Mint)

Enviado em 03/01/2014 - 12:37h


Alguns bugs sanados ...

E para não ser tao masoquista usando assembly puro ( sem funcoes ) ... implementei funcoes sem recursividade, pois demanda mais recursos( recursividade ) ...

Estou sentindo na pele usar somente assembly, ahaahah :)



;--------------------------------------------------------------------
;
; A simple example using function.
;
; USAGE:
; asmi function.asm
;
; BY: gokernel - gokernel@hotmail.com
;
;--------------------------------------------------------------------

long i

.str "\nFrom MY_FUNC - value of i: %d\n"

function my_func
push %ebp
mov %esp,%ebp
sub $8,%esp ; // set to 2 arguments

movl $1000,i

mov i,%eax
mov %eax,4(%esp)
mov str,%eax
mov %eax,(%esp)
call printf

leave ; // clear the stack ... using arguments
ret
end


;//<<<<<<< START MAIN >>>>>>>
push %ebp
mov %esp,%ebp

call my_func

call func ; // display the list functions
call word ; // display the list words

pop %ebp
ret









Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts