Hey i need help with converting Celsius to Fahrenheit.
Some reason its giving me a weird output. What seems to be the problem?
here is the original code
PAGE 80,132
;===================================================================
;
; PROGRAM LISTING 3.1
;
; PROGRAM TO CONVERT A TEMPERATURE FROM
; FAHRENHEIT TO CENTIGRADE USING THE FORMULA
;
; C = 5*(F-32)/9 ROUNDED TO NEAREST INTEGER
;===================================================================
DOSSEG
.MODEL SMALL,BASIC,FARSTACK
;===================================================================
;PROCEDURES TO
EXTRN GETDEC:FAR ;GET 16-BIT DECIMAL INTEGER
EXTRN NEWLINE:FAR ;DISPLAY NEWLINE CHARACTER
EXTRN PUTDEC:FAR ;DISPLAY 16-BIT DECIMAL INTEGER
EXTRN PUTSTRNG:FAR ;DISPLAY CHARACTER STRING
;===================================================================
;
; S T A C K S E G M E N T D E F I N I T I O N
;
.STACK 256
;===================================================================
;
; C O N S T A N T S E G M E N T D E F I N I T I O N
;
.CONST
PROMPT DB 'ENTER TEMPERATURE IN DEGREES FAHRENHEIT '
ANNOTATION DB ' TEMPERATURE IN DEGREES CENTIGRADE '
;===================================================================
;
; C O D E S E G M E N T D E F I N I T I O N
;
.CODE
EX_3_1:
MOV AX,SEG DGROUP ;SET ES-REGISTER TO ADDRESS
MOV ES,AX ; DGROUP
;
LEA DI,PROMPT ;PROMPT FOR F_TEMP
MOV CX,42
CALL PUTSTRNG
CALL GETDEC ;GET F_TEMP
SUB AX,32 ;C_TEMP = (F_TEMP -32) * 5 / 9
MOV BX,5
IMUL BX
MOV BX,9
IDIV BX
XCHG AX,DX ;REMAIN = (F_TEMP-32)*5 mod 9
MOV BL,5 ;ROUND = REMAIN / 5
IDIV BL
CBW
ADD AX,DX ;C_TEMP = C_TEMP + ROUND
;
LEA DI,ANNOTATION ;DISPLAY C_TEMP
; MOV CX,42
CALL PUTSTRNG
MOV BH,0
CALL PUTDEC
CALL NEWLINE
MOV AH,4CH ;RETURN TO DOS
INT 21H
END
;===================================================================
Here is my modified code
PAGE 80,132
;===================================================================
;
; PROGRAM LISTING 3.1
;
; PROGRAM TO CONVERT A TEMPERATURE FROM
; FAHRENHEIT TO CENTIGRADE USING THE FORMULA
;
; F = (9*C) /5+32 ROUNDED TO NEAREST INTEGER
;===================================================================
DOSSEG
.MODEL SMALL,BASIC,FARSTACK
;===================================================================
;PROCEDURES TO
EXTRN GETDEC:FAR ;GET 16-BIT DECIMAL INTEGER
EXTRN NEWLINE:FAR ;DISPLAY NEWLINE CHARACTER
EXTRN PUTDEC:FAR ;DISPLAY 16-BIT DECIMAL INTEGER
EXTRN PUTSTRNG:FAR ;DISPLAY CHARACTER STRING
;===================================================================
;
; S T A C K S E G M E N T D E F I N I T I O N
;
.STACK 256
;===================================================================
;
; C O N S T A N T S E G M E N T D E F I N I T I O N
;
.CONST
PROMPT DB 'ENTER TEMPERATURE IN DEGREES CELSIUS '
ANNOTATION DB ' TEMPERATURE IN DEGREES FAHRENHEIT '
;===================================================================
;
; C O D E S E G M E N T D E F I N I T I O N
;
.CODE
EX_3_1:
MOV AX,SEG DGROUP ;SET ES-REGISTER TO ADDRESS
MOV ES,AX ; DGROUP
;
LEA DI,PROMPT ;PROMPT FOR C_TEMP
MOV CX,42
CALL PUTSTRNG
CALL GETDEC ;GET C_TEMP
SUB AX,32 ;F_TEMP = (9 * C_TEAM) / 5+32
MOV BX,5
IMUL BX
MOV BX,9
IDIV BX
XCHG AX,DX ;REMAIN = (F_TEMP = (9 * C_TEAM) / 5+32
MOV BL,5 ;ROUND = REMAIN / 5
IDIV BL
CBW
ADD AX,DX ;F_TEMP = F_TEMP + ROUND
;
LEA DI,ANNOTATION ;DISPLAY F_TEMP
; MOV CX,42
CALL PUTSTRNG
MOV BH,0
CALL PUTDEC
CALL NEWLINE
MOV AH,4CH ;RETURN TO DOS
INT 21H
END
;===================================================================
hi Peedi,
It would be helpfull if you also provide us with the code of your EXTRN's.
Is that possible?
grt Rsir
Hi,
You should note that while the comments and strings were
updated, none of the working code changed.
Steve
I wouldn't waste your time on this one, guys. The source is obviously a weak attempt, and in a post that I removed the OP was trying to buy help with a test, that was to be on April 30.
Peedi, you probably have to read through the 'instruction set' book, especially on the workings of each instruction. :wink
It looks like you're making assumptions here... which is not a good thing when coding in asm.
Peedi,
MichaelW doesn't trust you.
Are you reliable?
Rsir
QuoteMichaelW doesn't trust you.
Trust has nothing to do with it. This looks to me very much like a lazy student trying to get someone else to do the work. The attempt failed and peedi departed, probably never to return.
Quote from: MichaelW on May 08, 2009, 12:36:23 PM
Trust has nothing to do with it. This looks to me very much like a lazy student trying to get someone else to do the work.
Student studies can be quiet hectic, and they do get desperate.... Maybe a little help - 'letting one slip by' won't do any harm...
It does look like a simple project ?
Maybe it might be an idea to make a Student forum section... after all if a student doesn't ask.. they do not get help.
Even if it is somebody else's work, they'll still have to learn it, and the teachers/lecturers are great detectives when it comes to plaguerism
It'll also help promote Assembler if you 'gettim' young....
:wink
I sort-of agree, and have been saying for years that we should be actively looking to "recruit" new members.
But alas, learning assembler is a demanding task, that can only be done either by those who have an oustanding memory capacity and moderate drive to learn, or those (like me) who have a shoddy memory but are eternally determined to learn. :bg
I have nothing in general against helping students, but I am not willing to waste my time trying to help someone who appears to me to be making no significant effort. Students who can learn a subject with no significant effort typically don't need help with the subject.
And since this is my second post in this thread after I decided not to waste time here, I guess I should point out the obvious "show stopper" error in the code, where it fails to initialize DS to the data segment.