Solved

Assembly questions

Posted on 2000-03-27
9
377 Views
Last Modified: 2010-04-02
QUESTION 1:
I have this program that calculates the factorial of numbers between 0 and 5 including them. The problem I have is that i want to write the final result to the variable called Fact and then print the resukt on screen, but it ain't working. Getting a warning.Here is what i Have:

;factorial of numbers

DATA SEGMENT
MES1 DB "ENTER NUMBER (0<=N<=5): $"
MES2 DB "THE RESULT IS: $"
FACT DB ?
DATA ENDS

STACK SEGMENT
DW 100 DUP(?)
STACK ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE

START:

MOV AX,DATA
MOV DS,AX

MOV AH,02H     ;making a return
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H

MOV AH,09     ;prompt for first number
MOV DX,OFFSET MES1
INT 21H

MOV AH,01 ;input first number
INT 21H
MOV BL,AL

MOV AH,02H ;making a return
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H

MOV BH,00H
MOV AX, BX
AAS ;adjust number to be decremented
MOV BX,AX

IF00: CMP BX,00
JNE ONE       ;routine for a 0 entry
THEN00: INC BX
MOV AX,1

ONE:
IF01: CMP BX,01  ;check if number is 1
JNE NOT_ONE    
THEN01: JMP CALC  ;jump to CALC
NOT_ONE: DEC BX

CALC: MUL BX
DEC BX
JNZ CALC

MOV DI,AX
MOV FACT,DI
AAM    ;adjust after multiplication

MOV CX,AX

MOV AH,00H
AAM
MOV BX,AX  ;BL contains the last digit of the result

MOV AL,CH
MOV AH,00H
AAM
MOV CX,AX  ;CX contains the first two digits of the resul

ADD CX, 3030H
ADD BX, 3030H ;adjust ASCII

MOV AH,09 ;output mess2
MOV DX,OFFSET MES2
INT 21H

MOV AH,02
MOV DL,CH
INT 21H
         ;print most significant digit
MOV AH,02
MOV DL,CL
INT 21H
         ;print middle digit
MOV AH,02
MOV DL,BL
INT 21H
           ;print last digit
MOV AH,4CH ;exit dos
INT 21H

CODE ENDS
END START







0
Comment
Question by:milalik
9 Comments
 

Author Comment

by:milalik
ID: 2662811
Question 2:

can anyone give me an example of how i deal with 16 bit signed numbers in Assembly. They include negative numbers. Please provide an example.Trying to do an array with ten signed numbers.
Thanx




0
 

Author Comment

by:milalik
ID: 2662815
Adjusted points from 50 to 70
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2662928
That is funny looking C++ :-)
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2663074
->can anyone give me an example of how i deal with 16 bit signed numbers in Assembly. They include negative numbers.
=========================
declare it and use a register as index.
K               word    ?
WArray          sword    0, -1, 2,- 3

mov K 1
;AX := WordAry[K]
mov     bx, K          
add     bx, bx
;Index*2 since this is a word array.
mov     ax, WordAry[bx]


Regards
W.Yinan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:milalik
ID: 2663888
For the second question, what if i want to enter it from the keyboard?
0
 
LVL 22

Accepted Solution

by:
nietod earned 75 total points
ID: 2663921
The problem is that you can't treat the bytes of a multi-byte number seperately like that.  You are trying to convert a 2 byte binary number to a 4 character ASCII number by converting the low byte to two digits and the high byte to two digits.  That can't work.  Consider 0100h which is 256 decimal.  You are going to get '00' from the the low byte and '01" from the high byte or "0100" which is the correct result--in hex.

you will need to divide the number by 1000 and look at the remainder, that is the 1st digt.  subtract off 1000* this digit and then divide by 100 to get the 2nd digit....
0
 

Author Comment

by:milalik
ID: 2664475
Is this for the first question or the second one?

Please correct the problem in the first question and provide and exmple that deals with 16 bits signed numbers if you can.

Thanx
0
 

Author Comment

by:milalik
ID: 2664484
Adjusted points from 70 to 75
0
 
LVL 22

Expert Comment

by:nietod
ID: 2665260
for the first question.  I'm not sure what the 2nd question even means.  but you are supposed to ask only one question per EE question (unless they are VERY closely related).  This is stated within the EE rules.  

I've outlined how you can perform the conversion.  Do you have any questions about it?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now