Home > Software design >  Tasm help needed
Tasm help needed

Time:01-14

Could someone give me a little help? It must be done in TASM 1.4, dividing 2 numbers like 14:2== 7. I tried for a few hours with tutorials from youtube but them all dont work. Some are for microsoft visual studio, which I can't use cause i must make it in the notepad. If anyone could help me you would save my day!

I tried coding the program but it tells me "Warning: no stack" and when i exe it, nothing pops out. I have few to almost none knowledge in assembly though.

The code I have tried is:

DATA SEGMENT
A DB 9 
B DB 6 
C DB ? 
D DB ? 
DATA ENDS 
CODE SEGMENT 
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,0
MOV AL,A
MOV BL,B
DIV BL
MOV C,AL
MOV D,AH
MOV AH,4CH
INT 21H
CODE ENDS
END START

CodePudding user response:

The reason it seems to not work is because your program doesn't contain any instructions to display output. You can tell the CPU to do math all day long, but if you never actually show it to the screen, you won't see anything. If you're getting started and want to see some numbers, it's easier to show numbers as hexadecimal than in base ten. (I don't have the code for it memorized but I'll edit this answer later with some sample code.)

CodePudding user response:

I did find an answer to the problem. I'll leave it here if anybody needs it, the program divides 2 numbers (2 digits numbers)

    ansprint macro res
    mov dl,res
    add dl,30h
    mov ah,02h
    int 21h        
    endm


    data segment
    msg1 db "Enter  one number $"
msg2 db 10,13,"Enter  second number $"
msg3 db 10,13,"result =  $"
msgdecimal db ".$"
a db 0
b db ?
decimal db 10 dup(0)    
data ends
                         
code segment
assume cs:code,ds:data
start:
            mov ax,data
            mov ds,ax
           
            ;displaying the message
            mov dx,offset msg1
            mov ah,09h
            int 21h
           
            ;taking the 1st input number
            mov ah,01h
            int 21h
            sub al,30h
            mov bh,al
            mov ah,01h
            int 21h
            sub al,30h
            mov bl,al
           
            ;combing two numbers
            mov ax,bx
            aad
            mov bx,ax
           
           
            ;displaying the 2nd  message
            mov dx,offset msg2
            mov ah,09h
            int 21h
           
            ;taking the 2st input number
            mov ah,01h
            int 21h
            sub al,30h
            mov ch,al
            mov ah,01h
            int 21h
            sub al,30h
            mov cl,al
           
            ;combing two numbers
            mov ax,cx
            aad
            mov cx,ax
            mov b,cl
           
            ;dividing the number
            mov al,bl
            div cl
            mov bl,ah
            aam
            mov cx,ax
           
            ;displaying the result message
            mov dx,offset msg3
            mov ah,09h
            int 21h
           
            ;displaying the result
            mov dl,ch
            add dl,30h
            mov ah,02h
            int 21h
           
            mov dl,cl
            add dl,30h
            mov ah,02h
            int 21h
           
            ;displaying the decimal
            mov dx,offset msgdecimal
            mov ah,09h
            int 21h
           
            ;spliting the decimal
            mov ch,00
            mov cl,05
           
    label1:         
            mov al,10
            mul bl ;bl contains the remainder part of the ans i.e. the ah part
            div b  ;b contains the 2nd number of the input
            mov bl,ah
            aam    ;spilts the number into decimal             
            mov decimal,al;store the number in the array          
            ansprint decimal
            loop label1
            mov cx,ax
                       
           
            ;terminate the program successfully
            mov ax,4c00h
            int 21h
    code ends
    end start
  • Related