-1

I have to redesign this code with the mov function to be written without an accumulator. I'm unsure of what this means, or how to do it. Could anyone help me out?

array1 DWORD 21H,22H,23H,24H,25H
array2 DWORD 31H,32H,33H,34H,35H

resultLbl1 BYTE "Array 1 values are",0
resultLbl2 BYTE "Array1 value1 is",0
resultLbl3 BYTE "Array1 value2 is",0
resultLbl4 BYTE "Array1 value3 is",0
resultLbl5 BYTE "Array1 value4 is",0
resultLbl6 BYTE "Array1 value5 is",0
string1 BYTE 40 DUP (?)
count DWORD 0

.CODE
_MainProc PROC

       ;add 2 to array1 elements

       mov eax, array1
       add eax, 2
       dtoa string1, eax
       output resultLbl1, string1

       mov eax, array1+4
       add eax, 2
       dtoa string1, eax
       output resultLbl1, string1

       mov eax, array1+8
       add eax, 2
       dtoa string1, eax
       output resultLbl1, string1

       mov eax, array1+12
       add eax, 2
       dtoa string1, eax
       output resultLbl1, string1

       mov eax, array1+16
       add eax, 2
       dtoa string1, eax
       output resultLbl1, string1
phuclv
  • 37,963
  • 15
  • 156
  • 475
user2796815
  • 465
  • 2
  • 11
  • 18
  • 2
    This sounds like nonsense. Obviously you can use any other register instead of EAX ("the accumulator"), but I don't see the point. You're not using EAX *as* an accumulator, just a separate temporary for each element. – Peter Cordes Dec 31 '19 at 04:10

2 Answers2

2

Let me propose a likely scenario of events...

Your teacher gave you code to display the elements in an array; and asked you to write code that adds 2 to the elements in an array. You didn't modify the elements in the array at all and only added 2 to the values that were read from the array (immediately before they're displayed).

Your teacher saw this, and instead of explaining that you aren't modifying the values in the array at all; they told you to do it without using an "accumulator" (a register), hoping that this would force you to use an instruction that actually does modify the array (and doesn't involve the use of any register for any reason).

Basically, I assume that your teacher wants you to do add array1,2, add array1+4,2, etc. Note: I use NASM where the correct syntax would be add dword [array1+4],2, and I don't know the syntax for whichever assembler you happen to be using (I've provided a "best guess" syntax that may be wrong).

Also note that if you add 2 to each element and then subtract 2 from each element; then each element would end up containing its original value.

Brendan
  • 35,656
  • 2
  • 39
  • 66
  • In the case of Microft's MASM (actually ML.EXE), since array1 is declared as dword, an add immediate to array1 should not require the operand dword type specifier. – rcgldr Feb 13 '14 at 08:15
-1
mov A, B

is equivalent to

xor A, A
add A, B; // or: or A, B

You can also do like this

xor A, A
xor A, B

Another way

lea A, [B + 0]
phuclv
  • 37,963
  • 15
  • 156
  • 475