MPL Assignment 3
MPL Assignment 3
Inx86-64assembly,datatypesdefinehowmuchmemoryisallocatedandhowthe
CPU interprets the data:
Examples
Affected Flags:
Instruction Condition
Algorithm:
1. Initialize max with the first element
Sample Code:
find_max_loop:
cmp rdx, rcx
jge find_max_done
skip_update:
inc rdx
jmp find_max_loop
find_max_done:
; rax contains max
Byte (8-bit)
Dword (32-bit)
Qword (64-bit)
Note:The scaling factor (*1, *2, *4, *8) matches the data size.
Basics
Q2. What are the general-purpose registers for each data size?
Intermediate
greater:
; Do something
continue:
Example:
minmax_loop:
cmp rdx, rcx
jge done
check_min:
cmp rbx, [rsi + rdx*8]
jle next
mov rbx, [rsi + rdx*8]
next:
inc rdx
jmp minmax_loop
done:
; rax = max, rbx = min
Q3. How to sort an array (bubble sort)?
outer_loop:
test r8, r8
jz done
mov r9, 0
inner_loop:
cmp r9, r8
jge next_outer
no_swap:
inc r9
jmp inner_loop
next_outer:
dec r8
jmp outer_loop
done:
; Sorted array
Summary
● Data Types: Byte to Qword, each with specific registers and scaling.
● Advanced Logic: Sorting, min-max in one pass, signed vs. unsigned
comparison handling.