Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake flag updates #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
44 changes: 44 additions & 0 deletions labs/Solutions/Lab10_jl.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
bits 64

global first_func, second_func, third_func

first_func:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Using the rdtsc instruction,
; 1.) Obtain the current timestamp
; 2.) Combine the low 32 bits (from RAX)
; and the high 32 bits (RDX), and
; return them.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
rdtsc
shl rdx, 32
add rax, rdx
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret

second_func:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Using CPUID, get the vendor
; string, and copy each chunk
; returned into the buffer
; passed to your function.
; The buffer should be the
; first (and only) argument.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
xor rax, rax
cpuid
mov [rdi], ebx
mov [rdi+4], edx
mov [rdi+8], ecx
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret


67 changes: 67 additions & 0 deletions labs/Solutions/Lab11_jl.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
bits 64

extern first_value
global first_func, second_func, third_func
global out1, out2

section .data

firstfloat dd 1.2345

secondfloat dd 2.345

out1 dd 0x00


out2 dq 0x00

tmp dq 0x00

section .text

first_func:
push rbp
mov rbp, rsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This problem will require
; you to load both firstfloat
; and secondfloat (above) onto
; the floating point stack, add
; them together, and store the
; result in out1.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
fld dword [firstfloat]
fld dword [secondfloat]
faddp
fstp dword [out1]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pop rbp
ret

second_func:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This problem will require
; you to add the contents of
; firstfloat to an integer
; that is passed in as the
; first (and only) argument
; to your function. Store the
; result at out2.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
fld dword [firstfloat]
mov [tmp], rdi
fild qword [tmp]
fadd
fstp qword [out2]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret


77 changes: 77 additions & 0 deletions labs/Solutions/Lab12_jl.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
bits 64

global first_func, second_func, third_func

firstdata dd 0x00
seconddata dd 0x00

first_func:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This problem will require
; adding two vectors of numbers.
; A pointer to two unaligned
; vectors of 32-bit integers
; have been passed as the first
; two parameters to your function,
; and a pointer to an empty
; vector has been provided to store
; the result.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
movups xmm0, [rdi]
movups xmm1, [rsi]
addps xmm0, xmm1
movups [rdx], xmm0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret

second_func:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This problem will require
; you to compare the values
; stored in the vector pointed
; to by parameter 1 with the
; values stored in the vector
; pointed to by parameter 2.
; Store the results of the
; comparison in the vector
; pointed to by parameter 3.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
movups xmm0, [rdi]
movups xmm1, [rsi]
cmpps xmm0, xmm1, 0
movups [rdx], xmm0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret

third_func:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Given two scalar values, passed
; in as two parameters, find the max
; of the two, and return it as your
; result.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
push rdi
push rsi
sub rdi, rsi
js less_than
pop rdi
pop rax
jmp done
less_than:
pop rax
pop rdi
done:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret
127 changes: 127 additions & 0 deletions labs/Solutions/Lab1_jl.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
bits 64

extern value
extern buf
extern val1
extern val2
global first_func, second_func, third_func, fourth_func, fifth_func, sixth_func

first_func:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This is your first method for
; the lab. First problem:
; move the number 16 into
; the register RAX.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov rax, 16
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret

second_func:
mov rcx, 0x20
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The second function in the lab
; involves moving a value from
; one register to another.
; Copy the contents of RCX into
; RAX.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov rax, rcx
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret


third_func:
mov rcx, value
mov rax, 0x10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The third function involves
; moving a value from a register,
; to a location in memory. RCX
; currently contains a pointer
; to some data. Copy the value
; from RAX to the location
; RCX points to.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov [rcx], rax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret


fourth_func:
mov rcx, value
xor rax, rax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; For the fourth function, copy
; the value stored in the
; location RCX points to into
; RAX.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov rax, [rcx]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret

fifth_func:
mov rcx, buf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; For this lab, you will need
; to use LEA to calculate the
; next address in a list of 8 byte
; elements, and then copy the value
; stored at that address into
; RAX.
; There is a a pointer to the
; beginning of the list stored
; in RCX.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
lea rcx, [rcx + 8]
mov rax, [rcx]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret

sixth_func:
mov rcx, val1
mov rdx, val2
xor rax, rax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; For this lab, you will need to
; use XCHG to swap two values
; stored in addresses in memory.
; The first value is a pointer to
; some data, contained by RCX, and
; the second is a pointer stored in
; RDX.
; HINT: Two XCHGs may be required.
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov rax, [rcx]
xchg rax, [rdx]
mov [rcx], rax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret


40 changes: 40 additions & 0 deletions labs/Solutions/Lab2_jl.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
bits 64

extern value
global first_func, second_func

first_func:
mov rax, -1
mov rcx, -1
mov cl, 0x04
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; For this task, you must move
; the first byte of RCX into
; RAX, using zero extend.
;
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
movzx rax, cl
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret


second_func:
xor rax, rax
mov ah, 0x42
mov al, 0x41
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; For this task, you must swap
; the contents of the first two
; bytes of RAX (ah/al).
;
; BEGIN student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
xchg al, ah
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END student code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret
Loading