; Kira Swab ; Assembly Language Programming ; March 2001 .model small .stack 100h .data ; This program uses input and output to calculate heating degree days ; for specified cities. titlestring db " Heating Degree Days Derived from City Temperatures",0 citystring db "City Name: ",0 cityname db 50 dup(0) lowstring db "Low Temperature: ",0 highstring db "High Temperature: ",0 lowtemp dw 0 lowesttemp dw 115 hightemp dw 0 highesttemp dw 0 tempbyte db 65 outcome1 db " had ",0 outcome2 db " heating degree days.",0 heatdays dw ? daysum dw 0 sumstring db "Total heating degree days for all the cities: ",0 loweststring db "Overall LOWEST temperature for all the cities: ",0 higheststring db "Overall HIGHEST temperature for all the cities: ",0 .code extrn Readstring:proc, Writestring:proc extrn Readint:proc, Writeint:proc, crlf:proc, Writeint_signed:proc main proc mov ax, @data mov ds, ax mov dx, offset titlestring call writestring call crlf info: call crlf call crlf mov dx, offset citystring ;sets dx to location of 1st string call Writestring ;writes 1st string with city name mov cx, 50 mov dx, offset cityname ;sets dx with location of 2cd string call Readstring ;reads a string of chars from input cmp ax, 0 ;if no city name, jumps to end je totals call crlf ;line feed, carriage return mov dx, offset lowstring ;sets dx location of low temp prompt call Writestring ;reads low temp string call Readint ;input an integer mov lowtemp, ax ;moves integer to lowtemp mov bx, ax cmp lowesttemp, ax ;compares to find lowest temp jg newlow ;if temp lower, then replaces lowmarker: call crlf mov dx, offset highstring ;sets dx location of hightemp prompt call Writestring ;reads hi temp string to output call Readint ;input an integer mov hightemp, ax cmp highesttemp, ax jl newhigh highmarker: call crlf add bx, ax ;adds the two temperatures sar bx, 1 ;divides by shifting to get average mov al, tempbyte ;moves 65 into register sub ax, bx ;subtracts the avg from 65, the norm temp jz none ;jumps to none if average is equal to 65 js none ;jumps to none if avg is greater than 65 jmp output none: mov ax, 0 ;if avg is >= 65, heat days = zero output: call crlf mov dx, offset cityname ;displays cityname call writestring mov dx, offset outcome1 ;writes output single city call Writestring add heatdays, ax ;moves heatdays to output mov bx, 10 ;moves decimal setting to output call writeint mov dx, offset outcome2 ;finishes city output call Writestring mov bx, 0 add bx, heatdays ;totals heating degree days mov daysum, bx jmp info ;jumps to beginning of loop totals: call crlf call crlf mov dx, offset sumstring ;outputs last city string call Writestring ; and total heating days mov ax, daysum call Writeint_signed call crlf ;outputs lowest temp mov dx, offset loweststring ; for all cities call Writestring mov ax, lowesttemp call Writeint_signed call crlf ;outputs highest temp mov dx, offset higheststring ; for all cities call Writestring mov ax, highesttemp call Writeint_signed call crlf jmp exit newlow: mov lowesttemp, ax jmp lowmarker newhigh: mov highesttemp, ax jmp highmarker exit: call crlf mov ax, 4c00h int 21h ;exit to DOS main endp end main