|
Prev: Survey
Next: Segment registers
From: patrick_woflian on 16 Mar 2006 10:24 Hey guys, this is a program i have made to convert a number into centigrade or fahrenheit.. depending on the users choice. it is made in textpad, via x86 and run in DOS (windows).. The first message 'please enter a number' works.. so does the 'enter C for centigrade or F for fahrenheit' depending on that, the next message works and outputs either 'the answer in fah is .... ' or 'the answer in cent is.....' which is very funky. However, The calculations do not work for some reason, im very stressed and in need of expert help!! or an eye for errors!! here is my code (whose layout is quite pretty!): JMP START ;skip over this part ;;;;;;;;;;;;;;;MESSAGES TO BE OUTPUT;;;;;;;;;;;;;;;;;;;;;; prompt DB ' Please enter a number to be converted', 13,10,"$" msg DB 'Please enter which you would like to change a number to, C or F? ', 13,10,"$" ;these are messages to be output to the user answer DB 'The answer is ', 13,10,"$" fahr DB 'The answer in fahrenheit is ',13,10,"$" celci DB 'The answer in centigrade is ',13,10,"$" ;;;;;;;;;;;;;;;;TEMPORARY VALUES;;;;;;;;;;;;;;;;;;;;;;;;;;; input DB ? tempA DB ? ;temporary values can be stored here tempB DB ? ;;;;;;;;;;;;;;ENTER A NUMBER FIRST!;;;;;;;;;;;;;;;;;;;;;;; START: ;enter number LEA DX,prompt MOV AH, 9 ;print first message to screen INT 21h MOV AH,1 INT 21H PUSH AX ;push first number entered into the stack ;;;;;;;;;;;;;;ENTER 'C' OR 'F' NEXT!;;;;;;;;;;;;;;;;;;;;;;;; CF: LEA DX,msg MOV AH, 9 ;print second message to screen INT 21h MOV AH,1 INT 21H ;save the second input ;;;;;;;;;;;;;;;;SUB ROUTINE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;sub routine ;this subroutine works out whether to convert into C or F before calling the either procedure CMP AL, 'F' JZ FAH CMP AL, 'C' JZ CENT ;depending on the input, move to 'CENT' or 'FAH' ;;;;;;;;;;;;;;;;FAHRENHEIT CALCULATIONS;;;;;;;;;;;;;;;;;;;;;;;;;; FAH: ;fahrenheit procedure POP AX MOV BX, 32D SUB AX,BX MOV BX, 5D MUL AX MOV BX, 9D DIV AX ;calculations made to number ((Number(-32)x5)/9) PUSH AX MOV AH,9 LEA DX,fahr MOV AH,9 INT 21h JMP FINISH ;output number and jump to 'FINISH' ;;;;;;;;;;;;;;;;;CENTIGRADE CALCULATIONS;;;;;;;;;;;;;;;;;;;;;;;;;;; CENT: POP AX ;centigrade procedure MOV BX, 9D MUL AX MOV DX,5D DIV AX ADD AX,32D ;calculations made to number ((number(x9)/5)+32) LEA DX,celci MOV AH,9 INT 21h JMP FINISH ;output number and jump to 'FINISH' ;;;;;;;;;;;;;;;;;;;;AND FINALLY..;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FINISH: MOV AH,4Ch ;exit program back to DOS INT 21h Please help, thank you very much.. >From a slightly fed up of ASM first year student Steve
From: James Daughtry on 16 Mar 2006 11:57 patrick_woflian wrote: > However, The calculations do not work for some > reason, im very stressed and in need of expert help!! or an eye for > errors!! I'm thinking that using AX as the explicit operand to DIV and MUL when AX is also the implicit operand is messing up your calculations. It's also a good idea to clear DX when dividing, because unless it's the 8-bit opcode, you're using DX:AX as the dividend, not just AX, and if DX isn't zero, it'll give you the wrong result. Am I right? Who knows? But it's a good guess. :-)
From: Rod Pemberton on 16 Mar 2006 12:16 "James Daughtry" <mordock32(a)hotmail.com> wrote in message news:1142528221.435723.189760(a)e56g2000cwe.googlegroups.com... > patrick_woflian wrote: > > However, The calculations do not work for some > > reason, im very stressed and in need of expert help!! or an eye for > > errors!! > > I'm thinking that using AX as the explicit operand to DIV and MUL when > AX is also the implicit operand is messing up your calculations. It's > also a good idea to clear DX when dividing, because unless it's the > 8-bit opcode, you're using DX:AX as the dividend, not just AX, and if > DX isn't zero, it'll give you the wrong result. > > Am I right? Who knows? But it's a good guess. :-) Simply your life a bit with these symmetric equations: F=(C+40)(9/5)-40 C=(F+40)(5/9)-40 You only need to conditionally change the order of operations for the fraction. Rod Pemberton
From: patrick_woflian on 16 Mar 2006 14:16 I was just wondering how to output the number really, i tried MOV DX, store in an attempt to output the number after calculations had taken place but it didnt work.. I also added a store DB " $" under messages at the top of the page.. It doesnt work.. any follow ups?
From: Evenbit on 16 Mar 2006 15:52
patrick_woflian wrote: > I was just wondering how to output the number really, i tried MOV DX, > store in an attempt to output the number after calculations had taken > place but it didnt work.. > > I also added a store DB " $" under messages at the top of the page.. > > It doesnt work.. any follow ups? Why should anyone bother to answer your questions when you don't even bother to read those answers? It is clear that you have no intention of learning how to write this program... you are simply posting bullshit for your own amuzement. Hope you are enjoying yourself! |