user15865261
user15865261

Reputation:

Modifying number of instructions into one

Currently my program uses three lines

    add    ax, Records[bx+4]
    add    ax, Records[bx+6]
    add    ax, Records[bx+8]

I was wondering can I modify the program to use a single instruction in a loop in place of the 3 instructions, as I will change both bx and the constant, I am unable to convert it into a single instruction.

Upvotes: 1

Views: 64

Answers (1)

Sep Roland
Sep Roland

Reputation: 39411

add    ax, Records[bx+4]
add    ax, Records[bx+6]
add    ax, Records[bx+8]

can I modify the program to use a single instruction in a loop

If you can live with writing a loop, then you'll have to accept that the loop comes with its overhead.
My reading of your sentence "use a single instruction" is that you want a single ADD AX, ... instruction performed in the loop.

Below is such a loop (same number of bytes [12]):

  mov si, 6
More:
  add ax, Records[bx+si+2]  ; First ..[bx+8] then ..[bx+6] then ..[bx+4]
  sub si, 2
  jnz More

Upvotes: 1

Related Questions