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

Write a MARIE assembly language program that will read an “array” of positive decimal values stored...
Write a MARIE assembly language program that will read an “array” of positive decimal values stored in memory and output the smallest value. Use variable addr to store the location of the first data item. Use variable length to store the number of items in your array. Your code should be organized such that adding an additional array item would only involve adding the data line (ie. 021 dec 400) and updating the length variable (ie. length, dec 5). You...
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...
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 in MIPS Assembly. This program will ask the user to enter 20 numbers....
Write a program in MIPS Assembly. This program will ask the user to enter 20 numbers. The program will store these numbers in an array in memory (sequential memory locations). It will then print out the list of numbers in three different formats: The numbers will be printed each on a separate line. The numbers will be printed on a single line, with spaces between the numbers. The program will ask the user to enter a number n. The program...
Write in assembly 8086. Write a program to input nine numbers in 4*4 array and prints...
Write in assembly 8086. Write a program to input nine numbers in 4*4 array and prints the maximum value of each row and then prints the minimum of each column.
Suppose you are provided with an array of integer values. Write pseudocode for a program to...
Suppose you are provided with an array of integer values. Write pseudocode for a program to determine how many unique values are in the array. Your solution should require time that is linearithmic in the size of the array. (For example, if the array contains the values {1,3,4,1,2}, the answer is "4", because the array contains the values 1, 2, 3, and 4)
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...
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
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT