Need help with 8086

Discussion in 'Programmer's Corner' started by Blink, Sep 30, 2011.

Thread Status:
Not open for further replies.
  1. Blink

    Thread Starter New Member

    Sep 30, 2011
    2
    0
    Hi im new to this website and very hope some one here can help me with this code.




    .MODEL SMALL
    .STACK 64h
    .DATA
    Number DW ?
    Cmd_Tail_Length DB 00h
    Cmd_Tail DB 11 DUP (' ')
    Error_Msg DB 'Error: command line tail not found or out of range.$'

    ;----------------------------------------------------------------------
    .CODE
    Main PROC FAR
    call Get_Command_Tail

    mov AX, @DATA
    mov DS, AX ; Make DS Point to our Data segment
    call Process_Cmd_Tail ; Procedure to process the command tail

    mov AX, @DATA
    mov ES, AX ; Make ES Point to our Data segment
    mov DS, AX ; Make DS Point to our Data segment
    mov SI, 80h

    mov CX, 05h
    call Process_Char
    cmp dl, 30h
    je ignore_zero
    call Display_Msg

    ignore_zero:
    mov CX, 04h
    call Process_Char
    cmp dl, 30h
    call Display_Msg

    mov CX, 03h
    call Process_Char
    cmp dl, 30h
    call Display_Msg

    mov CX, 02h
    call Process_Char
    cmp dl, 30h
    call Display_Msg

    mov CX, 01h
    call Process_Char
    call Display_Msg

    Finish:
    mov AX,4C00h ; Set parameters for
    int 21h ; Exit to DOS

    ;-----------------------------------------------------------------------
    Get_Command_Tail PROC NEAR
    ;Procedure to retrieve the DOS command tail string and store it in data segment in Cmd_Tail
    ;Inputs: None
    ;ES and DS will initially both point to the segment containing the PSP
    mov AX, @DATA
    mov ES, AX ; Make ES Point to our Data segment
    mov SI, 80h ; SI points to tail length
    mov CL, [SI] ; get the length
    mov ES:Cmd_Tail_Length, CL ; save it to data
    mov CH, 0 ; high part of count to 0
    mov SI, 81h ; SI poits to start of tail
    mov DI, offset Cmd_Tail ; DI points to buffer to save in memory
    rep movsb ; copy tail (block copy)
    mov ES:[DI], '$' ; put in terminating $ after tail (to stop string writes later)
    ret
    Get_Command_Tail ENDP
    ;-----------------------------------------------------------------------------
    Process_Cmd_Tail PROC NEAR

    cmp Cmd_Tail_Length, 0 ; check if tail length zero
    je Display_Error_Msg ; if equal (to zero) jump to different message
    mov SI, offset Cmd_Tail ; else SI point message to tail
    mov CX, 5h
    call Ignore_space ; ignore leading spaces

    proc_number_1:
    cmp [SI], 20h
    je next_number
    add AX, [SI]
    jo Display_Error_Msg
    mov BL, 10
    mul bl
    inc [SI]
    loop proc_number_1

    next_number:
    mov DX, AX
    mov Number, AX
    xor AX, AX
    inc [SI]
    mov CX, 5h
    call Ignore_space

    proc_number_2:
    cmp [SI], 20h
    je stop_next_number
    add AX, [SI]
    jo Display_Error_Msg
    mov BL, 10
    mul bl
    inc [SI]
    loop proc_number_2

    stop_next_number:
    mov DX, Number
    cmp AX, DX
    jl ax_less
    mov Number, AX

    ax_less:
    mov Number, DX
    ret
    Process_Cmd_Tail ENDP
    ;-----------------------------------------------------------------------
    ;-----------------------------------------------------------------------------
    Ignore_space PROC NEAR
    ;'Ignores' leading spaces in a string pointed to by SI by moving SI to first non-space char in string
    ; Inputs: SI = Start address of string
    ; Output: SI = Address of first non-space character
    ; Note: This is beyond the requirements of workshop, but is a 'nice to have' feature
    next_char:
    cmp [SI], 20h ; Compare with ' ' (space) character
    jne stop_ignore ; if not zero then exit
    inc SI ; else move pointer to next char
    jmp next_char ; go back and test next

    stop_ignore:
    ret
    Ignore_space ENDP
    ;-----------------------------------------------------------------------
    ;-----------------------------------------------------------------------
    Display_Error_Msg PROC NEAR
    ;Display a character interupt is used
    mov DX, OFFSET Error_Msg
    mov AH, 09h
    int 21h ; Service to display a $ terminated string
    jmp Finish
    ret
    Display_Error_Msg ENDP
    ;-----------------------------------------------------------------------
    ;-----------------------------------------------------------------------
    Process_Char PROC NEAR

    mov AX, Number

    again:
    mov BX, 10
    xor DX, DX
    div BX
    loop again
    add DL, 30h
    ret

    Process_Char ENDP
    ;-----------------------------------------------------------------------
    ;-----------------------------------------------------------------------
    Display_Msg PROC NEAR
    ;Display a character interupt is used

    mov AH, 02h
    int 21h
    ret
    Display_Msg ENDP
    ;----------------------------------------------------------------------
    This the homework question:
    Task 1 so that it is capable of reading two space separated decimal
    values in the range 0 – 65535 from the ​
    command tail, identifying the maximum of these two
    values, and displaying the result on the screen, before exiting to DOS. For example, if the
    following is entered at the command line:

    as1b 167 9755​
    Then your code should produce as output:​
    9755​
    Your code should produce an error message and exit if an incorrectly formatted input​
    (including out of range values) is supplied.

    for some reason it will always output some random value unless and only nothing has been entered is when the error message is displayed correctly. Please have a look at it and let me know where I have gone wrong as the logic I have used in this seems fine to me. I am not sure if the error is in Process_Cmd_Tail or Process_Char.

    Thankyou for all you guys help
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    This appears to be the same as your thread in the Homework section.
     
Loading...
Thread Status:
Not open for further replies.