0

I'm trying to learn assembly ussing the TASM compiler and the amount of information I found is very low. I'm ussing DOSbox and when I run the code I don't get the answer I was expecting. Can someone tell me what am I doing wrong here?

;Programm to add 2 numbers

datos segment

    ;X db?
    Base dw 10

datos endS

pila segment stack 'stack'
    dw 256 dup(?)
pila endS


codigo segment
    Assume  CS:codigo,DS:datos,SS:pila

main:
    mov ax, pila
    mov ss, ax

    mov ax,  datos
    mov  ds, ax

    ;programm
    mov ax, 15
    mov bx, 10 ;trying to have 15 and 10 as numbers in a variable to be added
    add ax, bx
    inc ax     ;adding 1
    mov ah, 02h;telling the program to print

    int  21h

    mov ax, 4C00h
    int 21h

codigo ends

end main

The result I got was a weird character, the result I was expeceting was 26 obviously. Do you know what's happening?

  • Well, INT 21 function 02 prints the ASCII character in DL, and you didn't initialize DL. If you were trying to write the string "26", then you will have to convert the integer to a string on your own. https://stackoverflow.com/questions/37644930/convert-integer-to-string-assembly-8086-tasm – Tim Roberts Feb 09 '22 at 04:03
  • Is there a way to print the intiger? – kpalacios Feb 10 '22 at 04:03
  • Well, yes, but you have to convert it, dividing by 10 to get each digit one at a time. The MS-DOS services can only print a string or a single character. Did you check the link up top to the question this one duplicates? – Tim Roberts Feb 10 '22 at 07:38
  • I tried but did not understand how it works. I think my logic in assembly programming is not enough developed. How should I learn the basics? – kpalacios Feb 11 '22 at 02:16
  • For the third time, I would direct you to the top of this page where it says "This question already has an answer here". One good way to learn assembly is to compile a C program, then step through it in a debugger. That way, you know what the program has to do. That won't help you with MS-DOS, of course, but that's not a saleable skill these days. – Tim Roberts Feb 11 '22 at 02:54

0 Answers0