Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

BAHRIA UNIVERSITY ISLAMABAD

Department of Computer Science

NAME MAHA-NOOR-ZAFAR

ENROLLMENT NUMBER 01-134212-078

SECTION 3A

TEACHER NAME Dr.MUHAMMAD ASFAND-E-YAR


ASSIGNMENT#4
Question 1:
Write an assembly language code of the following C++ function.
• Consider all the integers of this procedure as unsigned DWORD in Assembly Language.
• Write an Assembly code using the CALL instruction from the main body of Assembly
Language. (Don’t use INVOKE to call the procedure)
• Use accumulator to return the values from functions.
• Show the output from main body.
• Paste the Output Screens of Assembly Language.
o The output should be a complete Screen shot of your monitor screen, properly
visible output values.
(14)

int subtr (int x, int y) {


int var1=10; void main () {
int var2=50; :
:
int var4; int a = subtr ( 12, 10 )
:
var4 = var1 + var2; :

return var4 – ( x + y); }

CODE:

INCLUDE irvine32.inc
.data
var1 DWORD 0 ;declaring variables required within function
var2 DWORD 0
var4 DWORD 0
a DWORD 0 ;declaring variable required within main
.code
main PROC ;main starts
push 12 ;passing hardcore values as function arguments
push 10
CALL subtr ;calling function
mov a,eax ;storing value in variable a
CALL WriteDec ;printing answer
y_param EQU [ebp+12] ;declaring explicit stack parameter
x_param EQU [ebp+8] ;declaring explicit stack parameter
subtr PROC ;function defination
mov var1,10 ;intializing variable
mov var2,50 ;intializing variable
mov eax,var1 ;moving value to register
mov ebx,var2 ;moving value to register
add eax,ebx ;adding var1 and var2
mov var4,eax ;moving sum to var4
push ebp
mov ebp,esp
mov eax,y_param ;accesing second parameter
add eax,x_param ;accesing first parameter
mov ebx,eax ;copying value to ebx
mov eax,var4
sub eax,ebx
pop ebp
ret 8 ;clearing stack
subtr ENDP ;end of function defination

main ENDP ;end of main


END main

OUTPUT:

You might also like