; The purpose of this lab is to expose you to programming in assembly. You
; will gain first-hand experiance of the the joys and sorrows of this paradigm.
; You will be developing a Reverse-Polish-Notation calculator that uses the
; stack to pass arguments. In this laboratory you will be using jmp operations
; and the ecx register to pass between subroutines, do no use CALL and RET for
; your sub-routines, you should instead use a combination of:
; mov ecx, NextLine
; jmp StackXXXXXXXX
;
; to call an operation and
; jmp ecx
;
; to return to the instruction at the memory location stored in ECX
;
;
; ** For a full specification of the assignment, refer to your lab assignment.
;
; A Makefile is provided to assist in the compilation of your code
; $> make
;
; To run your code:
; $> ./lab6
;
; Your task will be assessed as follows:
;
; It should assemble (1 mark)
; Implement the StackAdd operation (2 marks)
; Implement the StackSubtract operation (2 marks)
; Implement the StackMultiply operation (2 marks)
; Implement the StackDivide operation (3 marks)
; Implement the StackModulo operation (3 marks)
; Implement the StackFactorial operation (5 marks)
; Implement the StackNChooseP operation (5 marks)
; Implement the StackEquals operation (2 marks)
;
;
;
;
; Good Luck!
;
;
%include "asm_io.inc"
%define overflow 0xFFFFFFFF ; A definition of the overflow value
%define NextLine $+10 ; this is a macro that will set the return address for
; your function
%macro printNewLine 0 ; this is a macro that will print a newline character
mov eax, newLine ; to the terminal
call print_string
%endmacro
;
; initialized data is put in the .data segment
;
segment .data
newLine: db 0xA,0
;
; uninitialized data is put in the .bss segment
;
segment .bss
;
; code is put in the .text segment
;
segment .text
global StackAdd, StackSubtract, StackMultiply, StackDivide, StackModulo, StackFactorial, StackNChooseP, StackEquals
StackAdd:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackSubtract:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackMultiply:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackDivide:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackModulo:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackFactorial:
add esp, 4 ; Clear the stack of one (4-byte) values
push 0
jmp ecx
StackNChooseP:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackEquals:
pop eax
mov eax, overflow ; YOU MUST REMOVE THIS LINE IN ORDER TO RECIEVE ANY
; MARKS (IF THIS IS REMOVED, StackEquals will work 100%)
jmp ecx
I HAVE A MAKEFILE READY WHICH IS INCLUDED IN THE ATTACHEMENT ALONG WITH OTHER FILES AND MORE INFOR ABOUT THIS LAB
; will gain first-hand experiance of the the joys and sorrows of this paradigm.
; You will be developing a Reverse-Polish-Notation calculator that uses the
; stack to pass arguments. In this laboratory you will be using jmp operations
; and the ecx register to pass between subroutines, do no use CALL and RET for
; your sub-routines, you should instead use a combination of:
; mov ecx, NextLine
; jmp StackXXXXXXXX
;
; to call an operation and
; jmp ecx
;
; to return to the instruction at the memory location stored in ECX
;
;
; ** For a full specification of the assignment, refer to your lab assignment.
;
; A Makefile is provided to assist in the compilation of your code
; $> make
;
; To run your code:
; $> ./lab6
;
; Your task will be assessed as follows:
;
; It should assemble (1 mark)
; Implement the StackAdd operation (2 marks)
; Implement the StackSubtract operation (2 marks)
; Implement the StackMultiply operation (2 marks)
; Implement the StackDivide operation (3 marks)
; Implement the StackModulo operation (3 marks)
; Implement the StackFactorial operation (5 marks)
; Implement the StackNChooseP operation (5 marks)
; Implement the StackEquals operation (2 marks)
;
;
;
;
; Good Luck!
;
;
%include "asm_io.inc"
%define overflow 0xFFFFFFFF ; A definition of the overflow value
%define NextLine $+10 ; this is a macro that will set the return address for
; your function
%macro printNewLine 0 ; this is a macro that will print a newline character
mov eax, newLine ; to the terminal
call print_string
%endmacro
;
; initialized data is put in the .data segment
;
segment .data
newLine: db 0xA,0
;
; uninitialized data is put in the .bss segment
;
segment .bss
;
; code is put in the .text segment
;
segment .text
global StackAdd, StackSubtract, StackMultiply, StackDivide, StackModulo, StackFactorial, StackNChooseP, StackEquals
StackAdd:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackSubtract:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackMultiply:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackDivide:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackModulo:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackFactorial:
add esp, 4 ; Clear the stack of one (4-byte) values
push 0
jmp ecx
StackNChooseP:
add esp, 8 ; Clear the stack of two (4-byte) values
push 0
jmp ecx
StackEquals:
pop eax
mov eax, overflow ; YOU MUST REMOVE THIS LINE IN ORDER TO RECIEVE ANY
; MARKS (IF THIS IS REMOVED, StackEquals will work 100%)
jmp ecx
I HAVE A MAKEFILE READY WHICH IS INCLUDED IN THE ATTACHEMENT ALONG WITH OTHER FILES AND MORE INFOR ABOUT THIS LAB