Question

In: Computer Science

Write an assembly program that rearrange the values in the following array as 40, 30, 20,...

Write an assembly program that rearrange the values in the following array as 40, 30, 20, 10:

.data byte1 BYTE 10, 20, 30, 40

Save the original four byte data into eax, and the rearranged data into ebx, from the least significant bit to the most significant bit. Insert a call DumpRegs statement to display the register values.

Solutions

Expert Solution

instruction    source offset     result
mov bx,[bx]     1000h             1BACh
mov cx,[si]     2000h             20FEh
mov bx,[ax]     illegal source register
add [si],[di]   illegal memory-memory add
inc [di]        3000h             031Eh

Processing Arrays using Register-Indirect Mode

  • Sum in ax the 10-element word array W

W   dw   10,20,30,40,50,60,70,80,90,10

xor ax,ax     ; ax holds sum
lea si,W      ; si points to array W
mov cx,10     ; cx has number of elements

addnos:

add ax,[si]   ; sum = sum + element
add si,2      ; move pointer to the next element
loop addnos    ; loop until done

  1. .code
  2. main PROC
  3. mov ax,8000h ;ax = 8000h
  4. mov bx,2000h ;bx = 2000h
  5. mov cx,3000h ;cx = 3000h
  6. sub ax,bx ;subtract bx from ax, ax = 6000h
  7. sub ax,cx ;subtract cx from ax, ax = 3000h
  8. sub cx,bx ;subtract bx from cx, cx = 1000h
  9. call DumpRegs ;display registers
  10. exit ;halt program
  11. main ENDP ;end procedure
  12. END main ;end program

Related Solutions

Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Write a program that does the following: Generate an array of 20 random integers between -100...
Write a program that does the following: Generate an array of 20 random integers between -100 and 100. Compute the average of the elements of the array and find the number of elements which are above the average. For example, if the elements of the array were 5 2 4 1 3 then your program should output The average is 3.0 There are two elements above the average Find the smallest element of the array as well as its index...
Write a program that uses an array of doubles initialized to whatever values you wish. Write...
Write a program that uses an array of doubles initialized to whatever values you wish. Write methods to calculate and return the minimum and a method to calculate and return the maximum value in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array as a parameter and then creates and returns a new array with all the same...
Thinking in Assembly language What values will be written to the array when the following code...
Thinking in Assembly language What values will be written to the array when the following code executes? .data array DWORD 4 DUP(0) .code main PROC mov eax,10 mov esi,0 call proc_1 add esi,4 add eax,10 mov array[esi],eax INVOKE ExitProcess,0 main ENDP proc_1 PROC call proc_2 add esi,4 add eax,10 mov array[esi],eax ret proc_1 ENDP proc_2 PROC call proc_3 add esi,4 add eax,10 mov array[esi],eax ret proc_2 ENDP proc_3 PROC mov array[esi],eax ret proc_3 ENDP
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements...
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements b) Inputs an integer n from 1-30 from the keyboard. If n < 1 set n = 1. If n > 30 set n = 30. the program should keep asking the user the input n one by one, followed by printing of the value of n (n=n if bigger than 1 and smaller than 30, 1 if smaller than 1 and 30 if...
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
Write a Java program that takes an array of 10 "Int" values from the user and...
Write a Java program that takes an array of 10 "Int" values from the user and determines if all the values are distinct or not. Return TRUE if all the values of the array are distinct and FALSE if otherwise.
1. a. In C++, Write a program that creates an array of 20 integers and initializes...
1. a. In C++, Write a program that creates an array of 20 integers and initializes it with the even values starting from 200. i.e. 200, 202, 204…. b. Write the elements of the array to the file even.txt, each element on a separate line. Try to use a single for loop for initializing the array and writing to file. You will need a separate counter for initializing the array. 2. a. Write another program that opens the file even.txt...
in MARIE simulator, write assembly language to BUBBLE SORT 30 hexadecimals store in two array.
in MARIE simulator, write assembly language to BUBBLE SORT 30 hexadecimals store in two array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT