Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey guys,
I'm new to assembler and my first assignment is to write code that ask from the user number between 00 to 99 and multiply by himself, for example the user enter 77, so 77*77=5929
i believe i'm having trouble to print back the result, This is my code so far :


**Update - i fixed my code and now its working

ASM
; lab34_2.asm
;
    .MODEL SMALL
    .STACK 100h     .DATA
Var1      DW ?
Res       DD ?
Ten       DW 10
PromptStr DB 'Please Enter Number (from 00 up to 99):',13,10,'$'
ResultStr DB 13,10,'Sqr(xx) =  xxxx',13,10,'$'
                            ;
     .CODE
     MOV AX,@DATA   ; DS can be written to only through a register
     MOV DS,AX      ; Set DS to point to data segment
     MOV AH,9
     MOV DX,OFFSET PromptStr
     INT 21h
;
;         Get the num , first digit
     MOV AH,1   
     INT 21h    
     MOV ResultStr[6],AL 
     SUB AL,'0'    
     MOV AH,0       
     MUL Ten       
     MOV Var1,AX
     MOV AX,0      
;          second digit
     MOV AH,1
     INT 21h
     MOV ResultStr[7],AL
     SUB AL,'0'
     MOV AH,0
     ADD AX,Var1
     MOV Var1,AX
;       Sqr
     MUL VAR1     ; DX:AX = VAR1*VAR1
     MOV WORD PTR Res,AX
     MOV WORD PTR Res+2,DX
;       Set res in the text
     DIV Ten
     ADD DX,'0'
     MOV ResultStr[16],DL
     MOV DX,0
;
    DIV Ten
     ADD DX,'0'
     MOV ResultStr[15],DL
     MOV DX,0
;
     DIV Ten
     ADD DX,'0'
     MOV ResultStr[14],DL
     MOV DX,0
;
     DIV Ten
     ADD DX,'0'
     MOV ResultStr[13],DL
     MOV DX,0
;
     MOV AH,9
     MOV DX,OFFSET ResultStr
     INT 21h
;
     MOV AH,4Ch       ; Set terminate option for int 21h
     INT 21h       ; Return to DOS (terminate program)
     END
Posted
Updated 15-Aug-13 2:34am
v2
Comments
_Asif_ 15-Aug-13 7:06am    
What assembler you are using ?
idobry 15-Aug-13 7:08am    
Dos Box
Sergey Alexandrovich Kryukov 15-Aug-13 7:55am    
What is the OS?
—SA
pasztorpisti 15-Aug-13 8:06am    
Those are pure dos int21h system calls.
Sergey Alexandrovich Kryukov 15-Aug-13 8:11am    
I know. That's why I'm asking. OP could naively use them, when OS is not DOS.
There is no such thing as "DOS box" in any modern OS...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900