(By using HCS12 assembly)You have a table of 10 Fahrenheit temperatures stored as words in Flash. Use the posted lab1_b.asm file as starting point. Write an assembly program that converts every Fahrenheit temperature element in Fahrs array into a Celsius temperature and stores the result at the corresponding element in Cels array. Use this relation: C = (5/ 9) * (F 32) for conversion. Because temperatures are signed, you will have to use signed multiplication and division instructions in your work.
lab1_b.asm file:
; export symbols
XDEF Entry,
_Startup
; export 'Entry' symbol
ABSENTRY Entry ; for
absolute assembly: mark this as application entry point
ROMStart: EQU
$4000
Temps_Count: EQU 10
; variable data goes in RAM
ORG $1000
Cels: DS.W 10 ; an array of 10 words!
; code section
ORG ROMStart
Entry:
_Startup:
; for every
F in Fahrs
; convert F into C
; store C into the corresponding location in
Cels
Here:
BRA Here
; an array of 10 constant words!
Fahrs: dc.w 0,20,40,60,80,100,120,140,160,180
;**************************************************************
;*
Interrupt
Vectors
*
;**************************************************************
ORG $FFFE
DC.W
Entry ;
Reset Vector
SOLUTION:
N.B : FOLLOWING code is compiled in assembly 8086 language .
data_seg segment
temp dw ? ; input number
ten dw 10 ; Defining constant ten for extracting the digits
Fahrs dw 1000 dup(?)
cels dw 1000 dup(?)
msg1 dw 10,13, ” Total how many temperature : $ ”
msg2 dw 10,13, ” enter temp in Fahrenheit: $ ”
msg3 dw 10,13, ”Temp. in Celsius are following : $ ”
five dw 5
nine dw 9
n dw ?
counter dw 0
data_seg ends
code_seg segment
assume cs: code_seg, ds: data_seg
print_string proc ; Procedure to print a string on monitor screen
pop si ; Save Top of Stack(ToS) content (Return Address) in SI register
pop dx
mov ah, 9 ; Put the service code for printing string on monitor screen
int 21h ; Invoke the Software Interrupt 21H
push si ; Push the saved Return Address onto the stack
ret ; Return to Main Program
print_string endp
read_char proc ; Procedure to read a character from key board
pop di ; Save top of stack content (Return Address) in DI register
mov ah, 1 ; Put service code for reading a character from keyboard
int 21h ; Invoke the Software Interrupt
mov ah, 0
push ax ; Push read character onto stack
push di ; Push the saved Return Address onto the stack
ret ; Return to the main program
read_char endp
read_number proc ; Procedure to read a number
pop si ; Pop the ToS content (the Return Address) into SI
mov bx,0 ; Initialize bx, dx
mov dx,0
next_digit:
call read_char
pop ax ; Get the read character in AX from ToS
cmp al, 0Dh ; Check if the input character is CR indicating end of the number
je done
sub al, 30h ; Convert ASCII to binary
mov cl, al ; Save the digit value in CX as a word
mov ch, 0 ;
mov ax, bx ; Get back the saved partial MS digits value to AX
mul ten ; Shift left the partial MS digits value by 1 digits
add ax, cx ; Add the last digit to the shifted MS digits value
mov bx, ax ; Save the new partial MS digits value in BX
jmp next_digit ; loop back read the next digit
done: push bx ; Push the read number onto the stack
push si ; Push the Return Address back on the ToS
ret ; Return to the main program
read_number endp
start:
mov ax, data_seg ; Initialize DS
mov ds, ax
push offset msg1 ; Print the Input Prompt Message on Screen
call print_string
call read_number ; Call the number read procedure.
pop dx ; Take the number into dx from ToS.
mov n, dx ; Place the input number in the n variable
lea di, Fahrs
lea bi cels
mov counter,0
repeat_step:
mov cx,n
cmp counter,cx
je print_part
push offset msg2 ; Print the Input Prompt Message on Screen
call print_string
call read_number ; Call the number read procedure.
pop dx
mov [di],dx
sub dx,32
mov ax,dx
mul five
div nine
mov [bi],ax
add bi,2
add di,2
inc counter
jmp repeat_step
printing_part:
lea dx ,msg3
mov ah,9
int 21h
mov cx,n
mov counter,cx
lea bi,cels
repeat_digit:
cmp counter ,0
je stop
mov dx,[bi]
mov ah,2
int 21h
add bi,2
dec counter
jmp repeat_digit
stop:
mov ah, 4ch ; Enter the service code to AH register
mov al, 0 ; Set return status of the program
int 21h ; Invoke the ISR to return the control to the Operating System
code_seg ends
end start
(By using HCS12 assembly)You have a table of 10 Fahrenheit temperatures stored as words in Flash....
I am having an issue with this practice problem. I understand the concept of given step, but I am lost to figure out how to setup in the main program in CodeWarrior software. Using the HCS12 Microcontrollers and Embedded Systems, 1st Edition, I was able to understand the instruction appendix, but I was not able to construct it in the main program. I need help to solve these steps and it is due today. Modify the Main program section of...