Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cs401 Computer Architecture and Assembly Language Programming 2 Solution May 10,2010
#1
[COLOR="red"]Write an assembly language Program that Compare two arrays of 10 elements. Arrays are given below

Array1: 10 15 20 25 30 35 40 45 50 55
Array2: 15 10 20 35 40 30 55 50 25 45

You have to compare the Array 2 element one by one with array1. Once the matching element found then compare the 2nd element of array 2 with array one and so on until the whole elements of array 2 are compared.

Due Date: 10-05-2010
[/COLOR]

Solution
hey kindly check this out i have no idea about this but it might help u..


I'd like to know what the exact phrasing of the question was.

It looks to me like they want you to sort the arrays first, in which case the two lists will agree.
(Array2 is a jumbled up version of array1.)


First, you need to specify which assembly language. I'm going to assume x86.
Then, you need to specify which assembler you're using: TASM? MASM? GASM? I'm going to assume TASM.
Then, you need to specify whether it is going to be a .COM file, a .EXE file, or a function. I'm going to assume a function called CompareArrays, and the arrays are FIXED, not passed into the function.
Then, you need to specify the target. 32-bit? 16-bit? I'm going to assume 32-bit.
Then, you need to know whether the arrays are arrays of bytes? Words? DoubleWords? I'm going to assume bytes.
Then, you have to say what to do when you FIND the element in Array2. I'm going to assume that you put the index of the element found in Array2 (starting from 0) in a third 10-element array called Result. If it's not found, then the element is -1.

Array1 DB 10,15,20,25,30,35,40,45,50,55
NumArray1 EQU $-Array1
Array2 DB 15,10,20,35,40,30,55,50,25,45
NumArray2 EQU $-Array2
Result DB NumArray1 DUP (-1) ; Pre-initialise to -1 (not found)

CompareArrays PROC

CLD ; Search forwards
MOV CH,OFFSET NumArray1 ; Number of elements to search
MOV EBX,OFFSET Result ; Point to Result
MOV ESI,OFFSET Array1 ; Point to first element of Array1

CompareLoop:
LODSB ; Get first number from ESI into AL
MOV CL,OFFSET NumArray2 ; Number of elements to compare
MOV AH,CL ; Save this away
MOV EDI,OFFSET Array2 ; Compare in Array2

REPNE SCASB ; Scan through array while NOT equal
JNE SHORT NextCompare ; Not found, so skip (already at -1)
SUB AH,CL ; Subtract from original number
DEC AH ; ...less one more for last compare
MOV [EBX],AH ; Save away into Result

NextCompare:
INC EBX ; Point to next Result
DEC CH ; One less to compare
JNZ CompareLoop

RET
CompareArrays ENDP
Source(s):
25 years of x86 assembler programming.

Please note, I haven't tested (or even assembled!) this - but you should get the idea.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cs403 Assignment 3 Helping material May 8,2010 viki 1 5,196 04-28-2020, 03:19 PM
Last Post: ClaireBeauc
  cs301 assignment no 3 Solution 20 January 2016 Vuhelper 0 11,086 01-20-2016, 03:32 PM
Last Post: Vuhelper
  CS201 Assignment vo 3 Solution 20th January 2016 Vuhelper 2 2,594 01-20-2016, 03:28 PM
Last Post: Vuhelper
  CS101 Assignment no 3 Solution 20th January 2016 Vuhelper 0 2,278 01-20-2016, 03:25 PM
Last Post: Vuhelper
  SOC101 INTRODUCTION TO SOCIOLOGY assignment no 3 Solution 20 January 2016 Vuhelper 0 1,868 01-20-2016, 03:19 PM
Last Post: Vuhelper
  CS402 Assignment No 4 Solution & Discussion Xpert 0 2,093 08-01-2015, 02:33 AM
Last Post: Xpert
  cs101 Assignment No. 1 Solution 21 may spring 2015 semester Xpert 0 2,907 05-21-2015, 12:41 AM
Last Post: Xpert
  Assignment solution eng 301 due date 20 may 2015 rumesa khan 3 4,526 05-20-2015, 01:34 AM
Last Post: Xpert
  PHY301 Circuit Theory Assignment No. 1 idea Solution spring may 2015 semester Xpert 0 1,557 05-15-2015, 03:52 AM
Last Post: Xpert
  Assignment No. 01 Spring 2015 Information Systems CS507 idea solution spring 2015 Xpert 0 2,445 05-15-2015, 03:49 AM
Last Post: Xpert

Forum Jump:


Users browsing this thread: 1 Guest(s)