home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug113.arc
/
OBESE.Z80
< prev
next >
Wrap
Text File
|
1979-12-31
|
5KB
|
197 lines
;+
; Program to determine Obesity by computing the Body Mass Index.
; BMI = Weight in Kilograms / (Height in metres squared )
;-
START: LD HL,TITLE ; Program title.
LD A,'.' ; Terminating character.
CALL OTL ; Print the title.
CALL CRLF ; Carriage return line feed.
CALL CRLF ;
LD HL,MESS2 ; Ask user for Weight
LD A,'.' ; Terminating character.
CALL OTL ; Print the question.
CALL IDEC ; User types a Decimal Number.
LD (WEIGHT),HL ; Store Weight in Kilograms.
CALL CRLF ;
LD HL,MESS3 ; Ask user for Height.
LD A,'.' ; Terminating Character.
CALL OTL ; Print the Question.
CALL IDEC ; User types a Decimal Number.
LD (HEIGHT),HL ; Store Height in Centimetres.
CALL CRLF ;
SEX1: LD HL,MESS4 ; Is user Male or Female ?
LD A,'.' ; Terminating Character.
CALL OTL ; Print Question
CALL MCHINW ; Get Single Character reply
CP 'M' ; M Is OK
JR Z,SEXOK ;
CP 'F' ; So Is F
JR Z,SEXOK ;
JR SEX1 ; Must be M or F
SEXOK: LD (SEX),A ; Save sex code
CALL CRLF ;
FRAM1: LD HL,MESS5 ; frame size ?
LD A,'.' ; Terminating Character
CALL OTL ; Print question
CALL MCHINW ; Get single character reply
CP 'M' ; MEDIUM is OK
JR Z,FRAMOK ;
CP 'L' ; LARGE is OK
JR Z,FRAMOK ;
JR FRAM1 ; Must be M or L
FRAMOK: LD (FRAME),A ; save frame
CALL CRLF
CALL CRLF
;+
; Make HIGH BYTES of data ZERO
;-
LD HL,0 ; get a 16 bit ZERO
LD (WH),HL ; 2 HIGH BYTES OF WEIGHT
LD (HH),HL ; 2 HIGH BYTES OF HEIGHT
LD (H2H),HL ; USED IN SQUARING HEIGHT
;+
; COMPUTE HEIGHT = (HEIGHT * HEIGHT)
;-
LD HL,(HEIGHT) ;
LD (HT),HL ; make a copy of Height
LD HL,HEIGHT ; so we can square it
LD DE,HT ;
LD B,4 ; 32 BIT number (4 BYTES)
CALL MPBMUL ; Multiply height by height
;+
; COMPUTE WEIGHT = WEIGHT * 10000
;-
LD HL,WEIGHT ; WEIGHT *
LD DE,FACT1 ; 10000
LD B,4 ; 32 BIT (4 BYTE) number
CALL MPBMUL ; multiply weight by 10000
;+
; COMPUTE WEIGHT = HEIGHT * 10000 / (WEIGHT*WEIGHT)
;-
LD HL,WEIGHT ; CONTAINS WEIGHT * 1000
LD DE,HEIGHT ; CONTAINS HEIGHT SQUARED
LD B,4 ; 32 BIT (4 BYTE) DIVIDE
CALL MPBDIV ; divide it
LD HL,(WEIGHT) ; answer to division
LD (BMI),HL ; Save BMI
PUSH HL ; save it for printing
LD HL,MESS8 ; Print the BMI message
LD A,'.' ; terminating character
CALL OTL ;
POP HL ; restore BMI
LD H,0 ;
CALL ODEC ; print it
CALL CRLF ;
CALL CRLF ;
SUB A ; CLEAR A
LD (OBESE),A ; CLEAR OBESE FLAG
LD A,(SEX) ; WHITCH SEX
CP 'M' ; MALE ?
JR Z,MALE ; yes
LD A,(FRAME) ; Frame type ?
CP 'M' ; MEDIUM ?
JR NZ,FATFEM ; NO
;+
; Medium frame female
;-
LD A,(BMI) ; Is BMI < 27?
CP 27 ;
JR C,PRINT ; yes not obese
LD (OBESE),A ; Obese is true
JR PRINT ;
;+
; Large Frame Female
;-
FATFEM: LD A,(BMI) ; is BMI < 30 ?
CP 30 ;
JR C,PRINT ; yes not obese
LD (OBESE),A ; Obese is true
JR PRINT ;
;+
; males
;-
MALE: LD A,(FRAME) ;
CP 'M' ; medium frame ?
JR NZ,FATMAN ; NO
;+
; Medium frame male
;-
LD A,(BMI) ; is BMI < 28 ?
CP 28 ;
JR C,PRINT ; yes not obese
LD (OBESE),A ; obese is true
JR PRINT
;+
; Large frame male
;-
FATMAN: LD A,(BMI) ; is BMI < 30 ?
CP 30 ;
JR C,PRINT ; yes not obese
LD (OBESE),A ; Obese is true
;+
; Print decision
;-
PRINT: LD A,(OBESE) ; Examine obese flag
OR A ;
JR Z,SKINNY ; Not obese if flag is ZERO
LD HL,MESS6 ; Tell the bad news
LD A,'.' ; terminating character
CALL OTL ;
CALL CRLF ;
JP START ; start again
SKINNY: LD HL,MESS7 ; Tell the good news
LD A,'.' ; terminating chatacter
CALL OTL ; print it
CALL CRLF ;
JP START ; start again
;+
; DATA
;-
HEIGHT: DW 0
HH: DW 0
WEIGHT: DW 0
WH: DW 0
HT: DW 0
H2H: DW 0
SEX: DB 0
FRAME: DB 0
BMI: DW 0
OBESE: DB 0
FACT1: DW 10000
DW 0
TITLE: DEFB ' Program to determine obesity .'
MESS2: DEFB ' How many Kilograms do you Weigh : .'
MESS3: DEFB ' What is your Height in Centimeters : .'
MESS4: DEFB ' Are you Male or Female (M/F) : .'
MESS5: DEFB 'Are you Medium or Large Frame (M/L) : .'
MESS6: DEFB ' Sorry but you are OBESE !!! .'
MESS7: DEFB ' Good news, you are NOT OBESE !! .'
MESS8: DEFB ' Your Body Mass Index is : .'
;+
; Subroutines required
;-
EXT MCHINW, IDEC, CRLF, OTL, MPBMUL, MPBDIV, ODEC, VDU
END
ur Body Mass Index is