0% found this document useful (0 votes)
49 views6 pages

Coal Lab 4

1. The document contains code snippets and exercises related to arrays and sorting in assembly language. It declares several arrays of different data types and performs operations like initializing variables, sorting arrays, copying elements between arrays, and adding elements using different addressing modes. 2. The exercises demonstrate initializing and accessing elements of arrays of byte, word, double word and using direct offset, indirect and indexed addressing to perform operations like sorting, copying and adding elements of the arrays. 3. Operations like initializing variables, sorting arrays in ascending order using registers, copying elements between arrays in reverse order, and adding selected elements of different arrays are demonstrated.

Uploaded by

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

Coal Lab 4

1. The document contains code snippets and exercises related to arrays and sorting in assembly language. It declares several arrays of different data types and performs operations like initializing variables, sorting arrays, copying elements between arrays, and adding elements using different addressing modes. 2. The exercises demonstrate initializing and accessing elements of arrays of byte, word, double word and using direct offset, indirect and indexed addressing to perform operations like sorting, copying and adding elements of the arrays. 3. Operations like initializing variables, sorting arrays in ascending order using registers, copying elements between arrays in reverse order, and adding selected elements of different arrays are demonstrated.

Uploaded by

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

COAL LAB 4

Rayyan Zafar 22k-4561

Exercises:

1. Declare a 32-bit signed integer val1 and initialize it with the eight thousand. If val1 is incremented

by 1 using the ADD instruction, what will be the values of the Carry and Sign flags?

Carry = 0

3. Initialize a double word array consisting of elements 8, 5, 1, 2 ,6. Sort the given array in

ascending order directly with the help of registers. Use direct-offset addressing to access the

elements.
INCLUDE Irvine32.inc

.data
arr DWORD 8,5,1,2,6
.code
main PROC
mov eax,arr+8
call writedec
call crlf
mov eax,arr+12
call writedec
call crlf
mov eax,arr+4
call writedec
call crlf
mov eax,arr+16
call writedec
call crlf
mov eax,arr
call writedec
call crlf

exit
main ENDP
END main

4. Use following array declarations:

arrayB BYTE 10, 20, 30

arrayW WORD 150, 250, 350

arrayD DWORD 600, 1200, 1800

Now initialize three double word variables SUM1, SUM2, SUM3 and perform following operations

(expressed in pseudo-code here):

SUM1 = arrayB[0] + arrayW[0] + arrayD[0]

SUM2 = arrayB[1] + arrayW[1] + arrayD[1]

SUM3 = arrayB[2] + arrayW[2] + arrayD[2]


INCLUDE Irvine32.inc
.data
arrayB BYTE 10, 20, 30
arrayW WORD 150, 250, 350
arrayD DWORD 600, 1200, 1800
SUM1 DWORD 0
SUM2 DWORD 0
SUM3 DWORD 0
.code
main PROC

mov esi,offset arrayB


mov edi,offset arrayW
mov ebx,offset arrayD

mov eax,DWORD PTR [esi]


add eax,DWORD PTR [edi]
add eax, ebx
mov SUM1, eax
call dumpregs
inc esi
add edi,2
add ebx,4
mov eax,DWORD PTR esi
add eax,DWORD PTR edi
add eax, ebx
mov SUM1, eax
call dumpregs
inc esi
add edi,2
add ebx,4
mov eax,DWORD PTR esi
add eax,DWORD PTR edi
add eax, ebx
mov SUM1, eax
call dumpregs

exit
main ENDP
END main
5. Initialize two arrays:

array1 BYTE 10, 20, 30, 40

array2 BYTE 4 DUP (?)

Copy elements of array1 into array2 in reverse order using either indirect addressing or direct-offset

addressing.
INCLUDE Irvine32.inc

.data
array1 BYTE 10, 20, 30, 40
array2 BYTE 4 DUP (?)
.code
main PROC
mov esi,offset array1
mov edi,offset array2
mov ecx,4
mov eax,0
L1:
mov al,[esi+3]
call writedec
call crlf
dec esi
mov [edi],al
inc edi
loop L1

exit
main ENDP
END main
7. Use following array declarations:
INCLUDE Irvine32.inc

.data
arrayB BYTE 10, 20, 30
arrayW WORD 150, 250, 350
arrayD DWORD 600, 1200, 1800
.code
main PROC
mov eax,0
mov esi,0
mov al,arrayB[esi * TYPE arrayB]
mov esi,2
add al,arrayB[esi * TYPE arrayB]
call dumpregs

mov eax,0
mov esi,0
mov ax,arrayW[esi * TYPE arrayW]
mov esi,2
add ax,arrayW[esi * TYPE arrayW]
call dumpregs

mov eax,0
mov esi,0
mov eax,arrayD[esi * TYPE arrayD]
mov esi,2
add eax,arrayD[esi * TYPE arrayD]
call dumpregs
exit
main ENDP
END main

You might also like