Results 1 to 3 of 3

Thread: [RESOLVED] It's ugly, but why won't it work?

  1. #1

    Thread Starter
    Hyperactive Member nothingofvalue's Avatar
    Join Date
    Jul 2005
    Location
    Arizona
    Posts
    489

    Resolved [RESOLVED] It's ugly, but why won't it work?

    Many thanks in advance to anyone who takes the time to help me out with this. I am new to assembly language and I really suck with it. Anyway, when I run this program it just keeps using Prompt1 three times and then displaying the either the accepted or rejected message.

    It appears that the math is correct since I am able to generate both messages, however, it obviously should be using three prompts. Also, the routine to check the length of each number entered is not working either. I think I had this mostly working and then I must have modified something and it stopped?

    Thanks again for any help.

    VB Code:
    1. Title Post Office Package Calculator
    2.  
    3.         ;this program will calculate the package size based on the height width and length entered by the user
    4.         ;if each dimension is 100 or less and the total dimensions add up to 108 or less the package will be accepted
    5.         ;if any dimension is over 100 or the total of the dimensions is over 108 then the package is rejected
    6.         ;will also allow user to exit program gracefully or continually enter new package dimensions
    7.        
    8. .model small   
    9.  
    10. .stack 100h     ;set our stack size to 100h (256 bytes)
    11.  
    12. .data       ;declare a segment for our variables
    13.  
    14. lf   equ 10
    15. cr   equ 13
    16.  
    17.         ;The three prompts the user will encounter
    18.        
    19.     Prompt1     db 'This program will determine if your package is able to be shipped by the Post Office.'
    20.             db 'If you wish to end the program enter [0] for the first dimension, otherwise please enter '
    21.             db 'the Height of your package : $', cr, cr,lf
    22.    
    23.     Prompt2     db 'Please enter the Length of your package :$', cr, cr,lf
    24.     Prompt3     db 'Please enter the Width of your package : $', cr, cr,lf
    25.    
    26.     Prompt4     db 'No dimension longer than 100 inches or less than 1 inch is acceptable.  This program will start over to allow you '
    27.             db 'to enter any other packages you may have. $', cr, cr,lf
    28.     Prompt5     db 'Your package has been accepted.$', cr, cr,lf
    29.     Prompt6     db 'Your pacakge does not meet postal requriments.$'
    30.            
    31.    
    32.    
    33. .code       ;declare a segment for our code
    34. extrn pstring : near
    35. extrn getdec  : near
    36.  
    37.    
    38. main PROC   ;declare a main procedure
    39.         ;always initialize DS to point to our Data segment
    40.        
    41. mov ax,@data    ;get the data segment address
    42.  
    43. mov ds,ax   ;and initialize the DS register to enable access to our variables
    44.         ;get the number X to convert
    45.         ;move our pointer to the right end of the output array 
    46.        
    47.        
    48. getnum proc     ;begin procedure 1
    49. mov dx, offset prompt1  ;Display prompt for first input
    50. call pstring        ;call to display the first prompt
    51. call getdec     ;accept the numeric input and convert to binary in AX
    52. call valtest        ;test for a value of zero or beyond limits
    53. getnum endp     ;end procedure
    54.  
    55.  
    56. getnum2 proc        ;begin procedure 2
    57. mov bx, ax      ;move value one to bx
    58. mov ax, 0
    59. mov ax, offset prompt2  ;prompt for second value
    60. call pstring        ;display message
    61. call getdec     ;accept the numeric and conver to binary in AX
    62. call valtest2       ;test for number above 100 or below 1
    63. getnum2 endp        ;end procedure
    64.  
    65.  
    66. getnum3 proc        ;Get the third number
    67. mov cx, ax      ;move value one to bx
    68. mov ax, 0
    69. mov ax, offset prompt3  ;prompt for third number
    70. call pstring        ;display message
    71. call getdec     ;accept the numeric and conver to binary in AX
    72. call valtest3       ;test for number above 100 or below 1
    73. getnum3 endp        ;end procedure
    74.  
    75.  
    76. valtest proc        ;test the first number
    77. cmp ax,0        ;compare ax to zero
    78. je @@done       ;if ax is zero then jump to wrongval
    79. cmp ax, 100     ;compare ax to max value
    80. ja @@wrongval       ;jumpt to wrongval if over 100
    81. cmp ax, 1       ;compare ax to minval
    82. jb @@wrongval       ;jumpt to wrongval if less than 1
    83. jmp getnum2     ;otherwise jump to the second input
    84. valtest endp
    85.  
    86.  
    87. valtest2 proc       ;test the second number
    88. cmp ax, 100     ;compare ax to max value
    89. ja @@wrongval       ;jumpt to wrongval if over 100
    90. cmp ax, 1       ;compare ax to minval
    91. jb @@wrongval       ;jumpt to wrongval if less than 1
    92. jnz getnum3     ;otherwise jump to the second input
    93. valtest2 endp
    94.  
    95.  
    96. valtest3 proc       ;test the third input
    97. cmp ax, 100     ;compare ax to max value
    98. ja @@wrongval       ;jumpt to wrongval if over 100
    99. cmp ax, 1       ;compare ax to minval
    100. jb @@wrongval       ;jumpt to wrongval if less than 1
    101. call comparelarge
    102. valtest3 endp
    103.  
    104.  
    105. comparelarge proc
    106. cmp ax, bx      ;compare values in ax and bx
    107. jbe L1          ;if ax is smaller jump to label 1
    108. mov ax, ax      ;else move ax to ax
    109. L1: cmp bx, cx      ;compare bx and cx
    110. jbe L2          ;if bx is smaller than cx jump to label 2
    111. add cx, cx      ;else add cx to cx
    112. L2:add ax, cx       ;add cx and ax
    113. add ax, bx      ;add ax and bx to get total number
    114. cmp ax, 108     ; make sure number is not over 108
    115. jbe L3          ; If 108 or under accept pacakge
    116. jmp L4          ; if over 108 reject package
    117. L3:
    118. mov dx, offset prompt5  ;display accept prompt
    119. call pstring
    120. call main
    121. L4:
    122. mov dx, offset prompt6  ;display reject prompt
    123. call pstring
    124. call main       ;start program over at beginning
    125. comparelarge endp
    126.  
    127.  
    128.  
    129.  
    130. @@wrongval:
    131. mov dx, offset prompt4  ;display wron dimension message
    132. call pstring
    133. call main       ;restart program
    134.  
    135.  
    136. @@done:
    137. mov ah, 4ch     ;OS function to terminate the program
    138. mov al, 0   ;supply the termination code
    139. int 21h     ;call the OS to execute the function to terminate the program
    140. main endp   ;demark the end of our main procedure
    141. end main    ;inform the assembler of the end of the source and specify the entry point
    "Imagination is more important than knowledge..."

    Albert Einstein
    -----------------------------------------------
    If my reply helped you then you really were lost, but I still took the time to help, please rate it anyway

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: It's ugly, but why won't it work?

    mov ax, offset prompt2
    mov ax, offset prompt3

    I don't know what pstring is looking for, but from 'mov dx, offset prompt1' I would assume that it expects dx to point to the string, not ax. Since dx is still pointing to prompt1, you're printing promt1 3 times.



    In your value tests, you're testing for 100 - base 16? That's 256 decimal.


    You're calling your tests, then jumping out of them - you're eating stack. Either call and return (the preferred way) or jump to them and jump out.


    In comparelarge, you're calling main?????? You can't call your program from within your program. Redo all the jumps and calls, so that you call a subroutine and return from it, then jump to where you want to go. If you want to restart the program, jump to main, don't call it.


    Try these things and see if it gets you closer to what you want.

  3. #3

    Thread Starter
    Hyperactive Member nothingofvalue's Avatar
    Join Date
    Jul 2005
    Location
    Arizona
    Posts
    489

    Re: It's ugly, but why won't it work?

    Thanks for the help. Unfortunately this stuff is just not clicking with me. I will keep hammering away and eventually get it. Thanks again.
    "Imagination is more important than knowledge..."

    Albert Einstein
    -----------------------------------------------
    If my reply helped you then you really were lost, but I still took the time to help, please rate it anyway

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width