+1 (315) 557-6473 

Create A Calculator In X86-64 Assembly For Linux Assignment Solution.


Instructions

Objective
Write a Linux assignment on ARM program to create a calculator in x86-64 assembly.

Requirements and Specifications

the calc program
Screenshots of output
Write a calculator in x86 64 assembly for Linux assembly language
Write a calculator in x86 64 assembly for Linux assembly language 1
Write a calculator in x86 64 assembly for Linux assembly language 2
Write a calculator in x86 64 assembly for Linux assembly language 3
Source Code
.intel_syntax noprefix
.text
.global _start
_start:
    #initialize rax to zero
    xor rax, rax
    #point to start of commands
    mov rbx, OFFSET [CALC_DATA_BEGIN]
loop1:
    # if the command is zero
    cmp BYTE PTR [rbx], 0
    # if zero, exit
    je done
    # advance to command argument
    add rbx, 8
    # call function
    call dummy
    # repeat loop
    jmp loop1
done:
    # exit
    mov rax, 60
    mov rdi, 0
    syscall
# dummy function that advances rbx by 8
dummy:
    add rbx, 8
    ret
.intel_syntax noprefix
.text
.global _start
_start:
    #initialize rax to zero
    xor rax, rax
    # initialize sums to zero
    mov QWORD PTR[SUM_NEGATIVE], rax
    mov QWORD PTR[SUM_POSITIVE], rax
    #point to start of commands
    mov rbx, OFFSET [CALC_DATA_BEGIN]
loop1:
    # load command
    mov cl, BYTE PTR [rbx]
    # advance to command argument
    add rbx, 8
    # if the command is zero
    cmp cl, 0
    # we are done
    je done
    # if the command is and
    cmp cl, '&'
    # do call function
    je do_and
    # if the command is or
    cmp cl, '|'
    # do call function
    je do_or
    # if the command is sum
    cmp cl, 'S'
    # do call function
    je do_sum
    # otherwise end
    jmp done
do_and:
    # call function
    call AND_FUNCTION
    # repeat loop
    jmp loop1
do_or:
    # call function
    call OR_FUNCTION
    # repeat loop
    jmp loop1
do_sum:
    # call function
    call SUM_FUNCTION
    # repeat loop
    jmp loop1
done:
    # exit
    mov rax, 60
    mov rdi, 0
    syscall
.intel_syntax noprefix
.text
.global _start
_start:
    #initialize rax to zero
    xor rax, rax
    # initialize sums to zero
    mov QWORD PTR[SUM_NEGATIVE], rax
    mov QWORD PTR[SUM_POSITIVE], rax
    #point to start of commands
    mov rbx, OFFSET [CALC_DATA_BEGIN]
loop1:
    # load command
    mov cl, BYTE PTR [rbx]
    # advance to command argument
    add rbx, 8
    # if the command is zero
    cmp cl, 0
    # we are done
    je done
    # if the command is and
    cmp cl, '&'
    # do call function
    je do_and
    # if the command is or
    cmp cl, '|'
    # do call function
    je do_or
    # if the command is sum
    cmp cl, 'S'
    # do call function
    je do_sum
    # otherwise end
    jmp done
do_and:
    # call function
    call AND_FUNCTION
    # repeat loop
    jmp loop1
do_or:
    # call function
    call OR_FUNCTION
    # repeat loop
    jmp loop1
do_sum:
    # call function
    call SUM_FUNCTION
    # repeat loop
    jmp loop1
done:
    # print last value of rax, save it first in temp
    mov QWORD PTR[temp], rax
    # load value of stdout
    mov rdi, 1
    # load address to be printed
    mov rsi, OFFSET [temp]
    # print 8 bytes
    mov rdx, 8
    # load write syscall
    mov rax, 1
    # write on stdout
    syscall
    # print last value of SUM_POSITIVE
    # load value of stdout
    mov rdi, 1
    # load address to be printed
    mov rsi, OFFSET [SUM_POSITIVE]
    # print 8 bytes
    mov rdx, 8
    # load write syscall
    mov rax, 1
    # write on stdout
    syscall
    # print last value of SUM_NEGATIVE
    # load value of stdout
    mov rdi, 1
    # load address to be printed
    mov rsi, OFFSET [SUM_NEGATIVE]
    # print 8 bytes
    mov rdx, 8
    # load write syscall
    mov rax, 1
    # write on stdout
    syscall
    # print values between CALC_DATA_BEGIN and CALC_DATA_END
    # load value of stdout
    mov rdi, 1
    # load address to be printed
    mov rsi, OFFSET [CALC_DATA_BEGIN]
    # calculate number of bytes to print
    # load end address
    mov rdx, OFFSET [CALC_DATA_END]
    # subtract start address
    sub rdx, rsi
    # load write syscall
    mov rax, 1
    # write on stdout
    syscall
    # exit
    mov rax, 60
    mov rdi, 0
    syscall
.data
    # place to save temporary values
    temp: .quad 0
.intel_syntax noprefix
.text
.global _start
_start:
    #initialize rax to zero
    xor rax, rax
    # initialize sums to zero
    mov QWORD PTR[SUM_NEGATIVE], rax
    mov QWORD PTR[SUM_POSITIVE], rax
    #point to start of commands
    mov rbx, OFFSET [CALC_DATA_BEGIN]
loop1:
    # load command
    mov cl, BYTE PTR [rbx]
    # advance to command argument
    add rbx, 8
    # if the command is zero
    cmp cl, 0
    # we are done
    je done
    # if the command is and
    cmp cl, '&'
    # do call function
    je do_and
    # if the command is or
    cmp cl, '|'
    # do call function
    je do_or
    # if the command is sum
    cmp cl, 'S'
    # do call function
    je do_sum
    # if the command is upper
    cmp cl, 'U'
    # do call function
    je do_upper
    # otherwise end
    jmp done
do_and:
    # call function
    call AND_FUNCTION
    # repeat loop
    jmp loop1
do_or:
    # call function
    call OR_FUNCTION
    # repeat loop
    jmp loop1
do_sum:
    # call function
    call SUM_FUNCTION
    # repeat loop
    jmp loop1
do_upper:
    # call function
    call UPPER_FUNCTION
    # repeat loop
    jmp loop1
done:
    # print last value of rax, save it first in temp
    mov QWORD PTR[temp], rax
    # load value of stdout
    mov rdi, 1
    # load address to be printed
    mov rsi, OFFSET [temp]
    # print 8 bytes
    mov rdx, 8
    # load write syscall
    mov rax, 1
    # write on stdout
    syscall
    # print last value of SUM_POSITIVE
    # load value of stdout
    mov rdi, 1
    # load address to be printed
    mov rsi, OFFSET [SUM_POSITIVE]
    # print 8 bytes
    mov rdx, 8
    # load write syscall
    mov rax, 1
    # write on stdout
    syscall
    # print last value of SUM_NEGATIVE
    # load value of stdout
    mov rdi, 1
    # load address to be printed
    mov rsi, OFFSET [SUM_NEGATIVE]
    # print 8 bytes
    mov rdx, 8
    # load write syscall
    mov rax, 1
    # write on stdout
    syscall
    # print values between CALC_DATA_BEGIN and CALC_DATA_END
    # load value of stdout
    mov rdi, 1
    # load address to be printed
    mov rsi, OFFSET [CALC_DATA_BEGIN]
    # calculate number of bytes to print
    # load end address
    mov rdx, OFFSET [CALC_DATA_END]
    # subtract start address
    sub rdx, rsi
    # load write syscall
    mov rax, 1
    # write on stdout
    syscall
    # exit
    mov rax, 60
    mov rdi, 0
    syscall
.data
    # place to save temporary values
    temp: .quad 0