In assembly language, reverse an array of integers:
# The array will be stored in memory
# The location of arr[0] is SP
# The location of arr[1] is SP+1
# The location of arr[2] is SP+2
# ... and so on
# The size of the array N will be stored in SP-1
# The SP register may be initialized to any value
2: 1024; # Initialize the SP register to 1024 (start of the
array)
# ALL other non-constant registers will be initialized to 0
# regardless of any initializers you use.
[1023]: 8; # N = 8 - the array has 8 elements
[1024]: 1; # arr[0] = 1
[1025]: -2; # arr[1] = -2
[1026]: 8; # arr[2] = 8
[1027]: 12; # arr[3] = 12
[1028]: -5; # arr[4] = -5
[1029]: 0; # arr[5] = 0
[1030]: 5; # arr[6] = 5
[1031]: 3; # arr[7] = 3
The goal is to get something like this:
# Goal:
#
# [1024]: 3;
# [1025]: 5;
# [1026]: 0;
# [1027]: -5;
# [1028]: 12;
# [1029]: 8;
# [1030]: -2;
# [1031]: 1;
#
1. Reverse an array
.data
array DWORD 1, -2, 8, 12, -5, 0, 5, 3 ;array to be reversed
.code
main proc
mov esi, 0
mov edi, 0
mov eax, 0
mov ebx, 0
mov esi, OFFSET array ;move first element address to esi
mov edi, OFFSET array + SIZEOF array - TYPE array
;move last element address to edi
mov ecx, LENGTHOF array / 2 ;sets the counter in the reverseLoop
reverseLoop:
mov eax, [esi] ;move the element in esi to eax
mov ebx, [edi] ;move the element in edi to ebx
xchg eax, ebx ;exchange the two elements
mov [esi], eax ;move the element in eax, to the address in esi
mov [edi], ebx ;move the element in ebx, to the address in edi
add esi, TYPE array ;increase esi to take the next element in the array (from the left)
sub edi, TYPE array ;decrease edi to take the next element in the array (from the right)
loop reverseLoop
invoke ExitProcess,0
main endp
end main
2. Assign to the new location : 1024
.data
A DW 1, -2, 8, 12, -5, 0, 5, 3 ; Array named 'A'
mov N, 8
; variable N = array size
I .BLOCK 1
; var i; // Numeric
A .BLOCK N
; var a = new array(8); //
Numeric
LOADIMM REGA, 0
;
TORE REGA, I
; i = 0;
LOOP LOAD REGA, I
; while (i < N)
LOADIMM REGB, 1024
; Base value of B = 1024
COMPARE REGA, REGB
;
BRANCH GE, ENDLP
;
LOADIMM REGA, 1
; Register A assigned the base address of array
a
LOAD REGB, I+1024
; Register B assigned the value of subscript
i+1024
ADD REGC, REGA,
REGB ; Register C assigned the address of
a[i+1024]
LOADIND REGA, REGB
STORE REGA, X ;
getting the value of a[i] and store into X an
integer
LOADIMM REGD, X
; Register D assigned the constant = array
value
STOREIND REGD, REGC
; a[i+1024] = X;
LOAD REGA, I
;
LOADIMM REGB, 1
;
ADD REGC, REGA,
REGB ;
STORE REGC, I
; i = i + 1;
JUMP LOOP
; }
ENDLP HALT
;
====
ARRAY D has stored all the required values.
In assembly language, reverse an array of integers: # The array will be stored in memory...
What is the local time in Denver, Colorado (US Mountain Standard Time) at the valid time of the surface weather chart below?What is the local time in Denver, Colorado (US Mountain Standard Time) at the valid time of the surface weather chart below? 002 13 NOV 2017 lsobors. Fronts. Rador &Dota Fronts at 002 020 7 31 1030 1023 1028 103 42 34 2536 24 5 741 218 306 35 32 303 3478 TH 1020 37 282 04 1008 26...
Problem 10-25 Resistors for electronic circuits are manufactured on a high-speed automated machine. The machine is set up to produce a large run of resistors of 1,000 ohms each. Use Exhibit 10.13 To set up the machine and to create a control chart to be used throughout the run, 15 samples were taken with four resistors in each sample. The complete list of samples and their measured values are as follows: Use three-sigma control limits. SAMPLE NUMBER 1 2 3...
Hi
2. (5pts) Given an array declaration: array[4][3] stored at memory location Ox1000, give an equation to find the element at the position array[2][1]. Assume the array is stored in row major order. "New Text Document (2) - Notepad File Edit Format View Help 5. (4pts) Give one advantage and one disadvantage of Pythons use of indentation to specify compound statements in control constructs.
Let S be a sequence of n distinct integers stored in an array as array elements S[1], S[2], · · · , S[n]. Use the technique of dynamic programming to find the length of a longest ascending subsequence of entries in S. For example, if the entries of S are 11, 17, 5, 8, 6, 4, 7, 12, 3, then one longest ascending subsequence is 5, 6, 7, 12. Specifically: (a) define a proper function and find the recurrence for...
Please answer 2.6.1
2.6 The table below shows 32-bit values of an array stored in memory Address Data 24 38 2 4 32 36 40 2.6.1 [5] <COD §§22, 2.3-For the memory locations in the table above, write C code to sort the data from lowest to highest, placing the lowest value in the smallest memory location shown in the figure. Assume that the data shown represents the C variable called Array, which is an array of type int, and...
Resistors for electronic circuits are manufactured on a high-speed automated machine. The machine is set up to produce a large run of resistors of 1,000 ohms each. Use Exhibit 10.13. To set up the machine and to create a control chart to be used throughout the run, 15 samples were taken with four resistors in each sample. The complete list of samples and their measured values are as follows: Use three-sigma control limits. SAMPLE NUMBER READINGS (IN OHMS) 1 1000...
Resistors for electronic circuits are manufactured on a high-speed automated machine. The machine is set up to produce a large run of resistors of 1,000 ohms each. Use Exhibit 10.13. To set up the machine and to create a control chart to be used throughout the run, 15 samples were taken with four resistors in each sample. The complete list of samples and their measured values are as follows: Use three-sigma control limits. SAMPLE NUMBER READINGS (IN OHMS) 1 992...
Given an array of integer, please complete a function multiply(). The function accepts the first memory address of an array and the size of an array as parameters and returns the multiplication of all the elements. In order to get a full score, the function must use a loop to iterate through each element of an array. Pseudo code example: multiply([ 1, 2, 3], 3) → 6 multiply([1, 1, 4 ,2], 4) → 8 multiply([7, 0, 0, 7, 0, 7],...
Write a program in ARM assembly language that copies each element of array A to consecutive fourth elements of array B, i.e., A[0] to B[0], A[1] to B[3], A[2] to B[7], etc. The array A is 12 elements long, and each element is a number that is 32 bits (1 word) wide. Assume the base address of array A is in register R2, and the base address of array B is in R3.
0 X 1.TX T 1 .III .2. 3 .III.4. III .5. III .6. II . , 7 . i. Resistors for electronic circuits are manufactured on a high-speed automated machine. The machine is set up to produce a large run of resistors of 1,000 ohms each. Use Exhibit 10.13 To set up the machine and to create a control chart to be used throughout the run, 15 samples were taken with four resistors in each sample. The complete list of...