0

I'm having some slight trouble with my program, my program is supposed to multiply together two 1-byte integers, using repeated addition.

BITS 16         ;Set code generation to 16 bit mode
ORG 0x0100      ;Set code start address to 0100h


SEGMENT .text       ;Main code segment

Main:
    mov CX,[num2]                                                    
    mov AX,00
Sum:
    add AX,[num1]
    dec CX
    cmp CX,0
    je Terminate
    jmp Sum

Terminate:
    mov DL,AL
    mov AX,4C00H
    int 21H

SEGMENT .data       ;Initialised data segment
    num1 db 4
    num2 db 3

The problem is that when I debug my code, the initial value (num2) is entered into CX fine, however when num1 is entered into AX, there is still some leftover data from num2.

Eg.Debug

As you can see from the image the value put into CX (3) works fine, however instead of putting 4 into AX, it puts 304.

Thanks for your help in advance.

1
  • Which assembler are you using? MASM? Commented Mar 14, 2013 at 22:50

1 Answer 1

1

That's because you load a 16-bit value into AX but your num1 value is one byte.

Do

  add al, [num1]

instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your response, is there a way to show the AL register in debug so I can see if it's worked or not?
I'm not familiar with the dev tools you use, but the AL register is always the lower half of the AX register you see on the debug screen (when viewed as hex).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.