0% found this document useful (0 votes)
6 views2 pages

Lab 09

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Lab 09

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Computer Organization and Assembly Language

Lab Task

Question 2: String Reversal


Write a procedure Reverse String that reverses a string passed via the stack:

 Pass the address of the string and its length as arguments via the stack.
 Save the flags using pushf and restore them with popf to preserve the status during string
manipulation.
 Use registers carefully and save them with pusha/popa if needed.

Question 3: Sorting an Array


Write a procedure Sort Array to sort an array of integers in ascending order:

 Pass the address of the array and the number of elements via the stack.
 Manually sort it without comparing values
 Protect all registers using pusha/popa.
 Display the sorted array in the main program using Kip Irvine’s WriteInt.

Test the procedure with the array: *[12, 3, 45, 7, 1, 9] *.

Question 4: Arithmetic Operations


Write a procedure Perform Operation that performs arithmetic operations (add, subtract,
multiply, divide) based on a flag:

 Push the operation code (1 for addition, 2 for subtraction, 3 for multiplication, 4 for
division) and two integers onto the stack.
 Save flags using pushf and restore them with popf.
 Protect registers using pusha/popa. Return the result on the stack.

Test the procedure with the following inputs:


1. Operation: Add (1), Operands: 25, 10
2. Operation: Multiply (3), Operands: 4, 5

Question 5: Fibonacci Sequence


Write a procedure GenerateFibonacci that generates the first n Fibonacci numbers:

 Pass the number of terms (n) and the address of an array to store the sequence via the
stack.
 Use pusha and popa to protect registers.
 Use pushf and popf where necessary to preserve flags during computations.
 The sequence should be generated iteratively.

Test the procedure with n = 10 and display the sequence using Kip Irvine's WriteInt.

Note:
USE Offset Operator for passing arrays as arguments on Stack.
e.g.:
MOV ECX, OFFSET ARRAY
PUSH ECX
mov ecx,[ebp+8]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy