Title Post Office Package Calculator
;this program will calculate the package size based on the height width and length entered by the user
;if each dimension is 100 or less and the total dimensions add up to 108 or less the package will be accepted
;if any dimension is over 100 or the total of the dimensions is over 108 then the package is rejected
;will also allow user to exit program gracefully or continually enter new package dimensions
.model small
.stack 100h ;set our stack size to 100h (256 bytes)
.data ;declare a segment for our variables
lf equ 10
cr equ 13
;The three prompts the user will encounter
Prompt1 db 'This program will determine if your package is able to be shipped by the Post Office.'
db 'If you wish to end the program enter [0] for the first dimension, otherwise please enter '
db 'the Height of your package : $', cr, cr,lf
Prompt2 db 'Please enter the Length of your package :$', cr, cr,lf
Prompt3 db 'Please enter the Width of your package : $', cr, cr,lf
Prompt4 db 'No dimension longer than 100 inches or less than 1 inch is acceptable. This program will start over to allow you '
db 'to enter any other packages you may have. $', cr, cr,lf
Prompt5 db 'Your package has been accepted.$', cr, cr,lf
Prompt6 db 'Your pacakge does not meet postal requriments.$'
.code ;declare a segment for our code
extrn pstring : near
extrn getdec : near
main PROC ;declare a main procedure
;always initialize DS to point to our Data segment
mov ax,@data ;get the data segment address
mov ds,ax ;and initialize the DS register to enable access to our variables
;get the number X to convert
;move our pointer to the right end of the output array
getnum proc ;begin procedure 1
mov dx, offset prompt1 ;Display prompt for first input
call pstring ;call to display the first prompt
call getdec ;accept the numeric input and convert to binary in AX
call valtest ;test for a value of zero or beyond limits
getnum endp ;end procedure
getnum2 proc ;begin procedure 2
mov bx, ax ;move value one to bx
mov ax, 0
mov ax, offset prompt2 ;prompt for second value
call pstring ;display message
call getdec ;accept the numeric and conver to binary in AX
call valtest2 ;test for number above 100 or below 1
getnum2 endp ;end procedure
getnum3 proc ;Get the third number
mov cx, ax ;move value one to bx
mov ax, 0
mov ax, offset prompt3 ;prompt for third number
call pstring ;display message
call getdec ;accept the numeric and conver to binary in AX
call valtest3 ;test for number above 100 or below 1
getnum3 endp ;end procedure
valtest proc ;test the first number
cmp ax,0 ;compare ax to zero
je @@done ;if ax is zero then jump to wrongval
cmp ax, 100 ;compare ax to max value
ja @@wrongval ;jumpt to wrongval if over 100
cmp ax, 1 ;compare ax to minval
jb @@wrongval ;jumpt to wrongval if less than 1
jmp getnum2 ;otherwise jump to the second input
valtest endp
valtest2 proc ;test the second number
cmp ax, 100 ;compare ax to max value
ja @@wrongval ;jumpt to wrongval if over 100
cmp ax, 1 ;compare ax to minval
jb @@wrongval ;jumpt to wrongval if less than 1
jnz getnum3 ;otherwise jump to the second input
valtest2 endp
valtest3 proc ;test the third input
cmp ax, 100 ;compare ax to max value
ja @@wrongval ;jumpt to wrongval if over 100
cmp ax, 1 ;compare ax to minval
jb @@wrongval ;jumpt to wrongval if less than 1
call comparelarge
valtest3 endp
comparelarge proc
cmp ax, bx ;compare values in ax and bx
jbe L1 ;if ax is smaller jump to label 1
mov ax, ax ;else move ax to ax
L1: cmp bx, cx ;compare bx and cx
jbe L2 ;if bx is smaller than cx jump to label 2
add cx, cx ;else add cx to cx
L2:add ax, cx ;add cx and ax
add ax, bx ;add ax and bx to get total number
cmp ax, 108 ; make sure number is not over 108
jbe L3 ; If 108 or under accept pacakge
jmp L4 ; if over 108 reject package
L3:
mov dx, offset prompt5 ;display accept prompt
call pstring
call main
L4:
mov dx, offset prompt6 ;display reject prompt
call pstring
call main ;start program over at beginning
comparelarge endp
@@wrongval:
mov dx, offset prompt4 ;display wron dimension message
call pstring
call main ;restart program
@@done:
mov ah, 4ch ;OS function to terminate the program
mov al, 0 ;supply the termination code
int 21h ;call the OS to execute the function to terminate the program
main endp ;demark the end of our main procedure
end main ;inform the assembler of the end of the source and specify the entry point