Question
x86-64 Assembly language Program Specifications You will need to write the following macros: 1. A macro that will take two 64 bit memory segments as
x86-64 Assembly language
Program Specifications You will need to write the following macros: 1. A macro that will take two 64 bit memory segments as arguments and swap their values. You must use the stack to hold at least one of the values temporarily. 2. A macro that takes a single memory address as an argument. This macro will need to eliminate any leading spaces. Count the number of spaces before any other letter appears. Push each character until (and including) the null character. Pop the characters back into their new place by adjusting the pointer according to the number of spaces counted. The macro should skip the pushes/pops if no leading spaces were found. 3. A macro that takes two arguments, a memory address to a qword variable and a memory address to a string. The string will contain a number in KMB format. The macro will calculate the integer value of the string and store it in the provided variable. Hint: The text will be formatted as follows: 0 or more spaces 0 or 1 - may appear 1 or more numerals (0 to 9)
0 or 1 . may appear 1 or more numerals (0 to 9) 1 k/K, m/M, or b/B
1 null
For k/K, the value must be multiplied by 1,000. For m/M, the value must be multiplied by 1,000,000. For b/B, the value must be multiplied by 1,000,000,000. Hint: Keep track of the number of digits that appear after a decimal point. Reduce the power of the KMB multiplier by that amount before multiplying.
14.15k = 1415 x 10(4-2) = 14,150 0.9k = 9 x 10(4-1) = 900
-16M = -1 x 16 x 10(6) = -16,000,000
You do not need to check for any errors or overflows.
****** Template ******
; Macro 1 - Swap two values ; Macro 2 - Remove leading spaces ; Macro 3 - KMB number string to integer
; Counts the number of characters in the null terminated string ; Returns the count in rdx %macro countStringLength 1 mov rdx, 1 mov rbx, %1 %%countStringLengthLoop: mov ch, byte[rbx] cmp ch, NULL je %%countStringLengthDone inc rdx inc rbx jmp %%countStringLengthLoop %%countStringLengthDone: %endmacro
section .data ; Do not modify these declarations SYSTEM_WRITE equ 1 SYSTEM_EXIT equ 60 SUCCESS equ 0 STANDARD_OUT equ 1 LINEFEED equ 10 NULL equ 0
macro1Label db "Macro 1: " oldValue db "Fails", LINEFEED, NULL newValue db "Works", LINEFEED, NULL
macro2Label db "Macro 2: " macro2message db " <- If you see a space, you must replace.", LINEFEED, NULL
macro3Label1 db "Macro 3-1: " macro3Label2 db "Macro 3-2: " macro3Label3 db "Macro 3-3: " macro3Number1 db "1.62k", NULL macro3Number2 db " -14.213M", NULL macro3Number3 db " 491B", NULL macro3Integer1 dq 0 macro3Integer2 dq 0 macro3Integer3 dq 0 macro3Expected1 dq 1620 macro3Expected2 dq -14213000 macro3Expected3 dq 491000000000 macro3Success db "Pass", LINEFEED, NULL macro3Fail db "Fail", LINEFEED, NULL
section .bss oldAddress resq 1 newAddress resq 1
section .text global _start _start:
mov rax, oldValue mov qword[oldAddress], rax mov rax, newValue mov qword[newAddress], rax
; Macro 1 ; Invoke macro 1 using qword[oldAddress] and qword[newAddress] as the arguments
; YOUR CODE HERE
; Macro 1 Test - Do not alter mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rsi, macro1Label mov rdx, 9 syscall mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rsi, qword[oldAddress] mov rdx, 6 syscall ; Macro 2 ; Invoke macro 2 using macro2message as the argument
; YOUR CODE HERE
; Macro 2 Test - Do not alter mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rsi, macro2Label mov rdx, 9 syscall mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rsi, macro2message countStringLength macro2message syscall ; Macro 3 - Test 1 ; Invoke macro 3 using macro3Integer1 and macro3Number1 as the arguments
; YOUR CODE HERE
; Macro 3 - Test 1 Results - Do not alter mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rsi, macro3Label1 mov rdx, 11 syscall mov rax, qword[macro3Expected1] cmp rax, qword[macro3Integer1] je macroTest3_1_success mov rsi, macro3Fail jmp macroTest3_1_print macroTest3_1_success: mov rsi, macro3Success macroTest3_1_print: mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rdx, 6 syscall ; Macro 3 - Test 2 ; Invoke macro 3 using macro3Integer2 and macro3Number2 as the arguments
; YOUR CODE HERE
; Macro 3 - Test 2 Results - Do not alter mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rsi, macro3Label2 mov rdx, 11 syscall mov rax, qword[macro3Expected2] cmp rax, qword[macro3Integer2] je macroTest3_2_success mov rsi, macro3Fail jmp macroTest3_2_print macroTest3_2_success: mov rsi, macro3Success macroTest3_2_print: mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rdx, 6 syscall ; Macro 3 - Test 3 ; Invoke macro 3 using macro3Integer3 and macro3Number3 as the arguments
; YOUR CODE HERE
; Macro 3 - Test 3 Results - Do not alter mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rsi, macro3Label3 mov rdx, 11 syscall mov rax, qword[macro3Expected3] cmp rax, qword[macro3Integer3] je macroTest3_3_success mov rsi, macro3Fail jmp macroTest3_3_print macroTest3_3_success: mov rsi, macro3Success macroTest3_3_print: mov rax, SYSTEM_WRITE mov rdi, STANDARD_OUT mov rdx, 6 syscall endProgram: mov rax, SYSTEM_EXIT mov rdi, SUCCESS syscall
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started