Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

question about assembly language?

my question is if i want to add number by the number before it for example 4+3+2+1+0=10

how i can do it by using emu8086 i try by using there code but it had many error

include 'emu8086.inc'

org 100h

mov ax,4

mov bx,0

add ax,bx

jz a

dec ax,1

add ax,bx

jmp exit

2 Answers

Relevance
  • Ken
    Lv 4
    3 years ago

    You have 2 jumps but show no labels to jump to. Adding those would help :)

  • 3 years ago

    Looks like you're using 16-bit instructions. For that, you can

    mov bx,4 ; first term

    mov ax,0 ; sum of terms starts at zero

    new_term: ; return here to add a new term

    add ax,bx ; add current term to sum

    dec bx ; next term is 1 less than previous

    jge new_term

    ; now ax = 4 + 3 + 2 + 1 + 0

    Change the final "jge" to "jg" or "jnz" to skip adding the final 0.

    If you know how, use a "trace" of that and watch what happens to the registers on each instruction. If not....learn how! Or you can single-step and watch; but some GUI type interfaces won't show you a history of what happened--just the current state. You miss out on some of the dynamics.

Still have questions? Get your answers by asking now.