In: Computer Science
**Add comments to ARM code to explain steps**
Write an ARM assembly program to convert temperatures from Celsius to Fahrenheit or from Fahrenheit to Celsius. Here are the two formulas for your reference. Use variable to read and store values.
C= 5* (F - 32) / 9
F = (9 * C / 5 ) + 32
TempConvert.s
LDR R8,=temperature
LDR R1,[R8]
LDR R8,=unit
LDRB R2,[R8]
LDR R8,=celsius
LDRB R3,[R8]
LDR R8,=fahrenheit
LDRB R4,[R8]
MOV R6,#9
MOV R7,#5
;----C = 5 * (F - 32) / 9
SUB R5,R1,#32
MUL R5,R5,R7
UDIV R5,R5,R6
;------F = (9 * C / 5) + 32
MUL R5,R1,R6
UDIV R5,R5,R7
ADD R5,R5,#32
stop B stop
temperature DCD 50
unit DCB "F",0
celsius DCB "C",0
fahrenheit DCB "F",0
END
Assembly program to convert temperatures from Celsius to Fahrenheit. DATA SEGMENT T DB ? RES DB 10 DUP ('$') MSG1 DB "ENTER TEMPERATURE IN CELSIUS (ONLY IN 2 DIGITS) : $" MSG2 DB 10,13,"CONVERTED IS FAHRENHEIT (TEMPERATURE) : $" DATA ENDS CODE SEGMENT ASSUME DS:DATA,CS:CODE ;START is the label used to show the starting point of the code which is written in the Code Segment. START: MOV AX,DATA MOV DS,AX ;move contents of AX into DS LEA DX,MSG1 MOV AH,9 ;move 9 into AH INT 21H MOV AH,1 INT 21H SUB AL,30H MOV AH,0 MOV BL,10 MUL BL MOV BL,AL MOV AH,1 INT 21H SUB AL,30H MOV AH,0 ADD AL,BL MOV T,AL MOV DL,9 MUL DL MOV BL,5 DIV BL MOV AH,0 ADD AL,32 LEA SI,RES CALL HEX2DEC LEA DX,MSG2 MOV AH,9 INT 21H LEA DX,RES MOV AH,9 INT 21H MOV AH,4CH INT 21H CODE ENDS HEX2DEC PROC NEAR MOV CX,0 MOV BX,10 LOOP1: MOV DX,0 DIV BX ADD DL,30H PUSH DX INC CX CMP AX,9 JG LOOP1 ADD AL,30H MOV [SI],AL LOOP2: POP AX INC SI MOV [SI],AL LOOP LOOP2 RET HEX2DEC ENDP END START