;
; CI-0118
; Grupo 2 (Fco. Arroyo)
;
; Modulos en ensamblador para la clase Vector
;
; Assemble: nasm -f elf64 vector.asm
; Compile: g++ -g testVector.cc Vectoc.cc vector.o -o testVector.out
;
extern malloc
extern free
section .text
global init ; Vector::Vector( int size )
global destroy ; Vector::~Vector()
global allset ; Vector::allSet( long value )
global eleset ; Vector::set( int position, long value )
global eleget ; Vector::get( int position )
; ---------------------------------------------------------------------------
init: ; For class constructor
shl rdi, 3 ; use 64 bits words
xor rax, rax ; set AX to zero
push rdi ; malloc need its parameter to be pushed on stack, it is a normal call
call malloc ; AX will have a pointer to new allocated space
pop rdi
ret
; ---------------------------------------------------------------------------
destroy: ; For class destructor
push rdi
call free
pop rdi
ret
; ---------------------------------------------------------------------------
allset: ; For method "allSet" DI address, SI size, DX value
mov rcx, rsi
xor rsi, rsi
next:
mov [ rdi + rsi * 8 ], rdx
inc rsi
loop next
ret
; ---------------------------------------------------------------------------
eleset: ; For "set" method: DI address, SI position, DX value
mov [rdi + rsi * 8], rdx
ret
; ---------------------------------------------------------------------------
eleget: ; For "get" method: DI address, SI position
mov rax, [ rdi + rsi * 8 ]
ret