Question: . data ; Declare constants DAYS _ MEASURED equ 1 4 ; Number of days measured TEMPS _ PER _ DAY equ 1 1 ;

.data ; Declare constants DAYS_MEASURED equ 14 ; Number of days measured TEMPS_PER_DAY equ 11 ; Number of temperatures per day MIN_TEMP equ 20 ; Minimum temperature MAX_TEMP equ 80 ; Maximum temperature ARRAYSIZE equ DAYS_MEASURED * TEMPS_PER_DAY ; Total number of temperatures ; Declare arrays tempArray db ARRAYSIZE dup(?) ; Store all temperature readings highTemps db DAYS_MEASURED dup(?) ; Store daily high temperatures lowTemps db DAYS_MEASURED dup(?) ; Store daily low temperatures highAvg dw 0 ; Average high temperature lowAvg dw 0 ; Average low temperature ; Declare messages msgIntro db "Temperature Data Program - Generated by YourName", 0 msgTemperature db "Temperature Readings for Each Day:", 0 msgHighTemps db "Daily High Temperatures:", 0 msgLowTemps db "Daily Low Temperatures:", 0 msgHighAvg db "Average High Temperature:", 0 msgLowAvg db "Average Low Temperature:", 0.code main: ; Initialize the data segment mov ax, @data mov ds, ax ; Display intro message lea dx, msgIntro mov ah,09h int 21h ; Seed the random number generator call Randomize ; Generate the temperature data lea di, tempArray mov cx, DAYS_MEASURED generate_data: push cx mov bx, TEMPS_PER_DAY mov si,0 generate_day_data: call RandomRange mov [di], al inc di inc si loop generate_day_data pop cx loop generate_data ; Find the high and low temps for each day lea di, tempArray lea si, highTemps lea bx, lowTemps mov cx, DAYS_MEASURED process_days: push cx mov ax,0 ; Reset high temp for the day mov bx,255 ; Set low temp for the day to the highest possible value mov dx, TEMPS_PER_DAY process_temps: mov al,[di] cmp al, ax jg update_high cmp al, bx jl update_low jmp next_temp update_high: mov ax, al jmp next_temp update_low: mov bx, al next_temp: inc di loop process_temps mov [si], ax ; Store high temp mov [bx], bx ; Store low temp inc si inc bx pop cx loop process_days ; Calculate the average high and low temperatures lea si, highTemps lea bx, lowTemps xor ax, ax ; Clear sum for high temps xor dx, dx ; Clear sum for low temps mov cx, DAYS_MEASURED calculate_averages: add ax,[si] ; Add high temp to sum add dx,[bx] ; Add low temp to sum inc si inc bx loop calculate_averages ; Truncate the averages mov bx, DAYS_MEASURED div bx ; Divide sum of high temps by DAYS_MEASURED mov highAvg, ax ; Store average of highs mov lowAvg, dx ; Store average of lows ; Display the temperature data lea dx, msgTemperature mov ah,09h int 21h lea di, tempArray mov cx, DAYS_MEASURED call display_day_data ; Display daily high temperatures lea dx, msgHighTemps mov ah,09h int 21h lea di, highTemps call display_day_data ; Display daily low temperatures lea dx, msgLowTemps mov ah,09h int 21h lea di, lowTemps call display_day_data ; Display the average high and low temperatures lea dx, msgHighAvg mov ah,09h int 21h mov ax, highAvg call display_number lea dx, msgLowAvg mov ah,09h int 21h mov ax, lowAvg call display_number ; Exit program mov ah,4Ch int 21h RandomRange proc ; Generate a random number in the range [MIN_TEMP, MAX_TEMP] ; The logic for generating the random number can be implemented here using DOS interrupt for randomness ; For simplicity, returning a number between MIN_TEMP and MAX_TEMP (inclusive) mov al, MIN_TEMP +(randVal mod (MAX_TEMP - MIN_TEMP +1)) ret RandomRange endp display_day_data proc push cx mov cx, TEMPS_PER_DAY display_temp_loop: mov al,[di] call display_number inc di loop display_temp_loop pop cx ret display_day_data endp display_number proc ; Display a number mov ah,02h add ax,'0' int 21h ret display_number endp use only irvine32.inc

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!