Getting started in assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 219
Number of posts: 577

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
emu8086 help Posted by super.rad on 17 Jan 2007 at 9:00 AM
Hi, im studying music and audio electronic systems in uni and i've been set an assingment for my microprocessor lecture. the assignment is:

Write a program in (8088) assembly language that should be able to:
Input any number of positive values of two decimal digits using DOS services.
Find the maximum value.
Display the number of values and the maximum value using DOS services.
Comment on the limitations of your program.

the software i have to use is emu8086 http://www.emu8086.com/

basically i have no clue where to start or what to do and never done any programming or used this software before, so anyone who knows a bit about programming and has used the software if you could give a few hints or anything i would be very grateful.
Report
Re: emu8086 help Posted by MT2002 on 20 Jan 2007 at 9:24 AM
: Hi, im studying music and audio electronic systems in uni and i've been set an assingment for my microprocessor lecture. the assignment is:
:
: Write a program in (8088) assembly language that should be able to:
: Input any number of positive values of two decimal digits using DOS services.

What do you mean by of two decimal digits? Do you mean two digits (ie, 23), floating point (ie 0.23), or two different numbers that require seperate inputs?

: Find the maximum value.

What do you mean here?

: Display the number of values and the maximum value using DOS services.
: Comment on the limitations of your program.
: the software i have to use is emu8086 http://www.emu8086.com/
:
: basically i have no clue where to start or what to do and never done any programming or used this software before, so anyone who knows a bit about programming and has used the software if you could give a few hints or anything i would be very grateful.
:

Please elabrate on your original post, and I will see what I can do.


Report
Re: emu8086 help Posted by super.rad on 20 Jan 2007 at 10:13 AM
: : Hi, im studying music and audio electronic systems in uni and i've been set an assingment for my microprocessor lecture. the assignment is:
: :
: : Write a program in (8088) assembly language that should be able to:
: : Input any number of positive values of two decimal digits using DOS services.
:
: What do you mean by of two decimal digits? Do you mean two digits (ie, 23), floating point (ie 0.23), or two different numbers that require seperate inputs?
:

: : Find the maximum value.
:
: What do you mean here?
:

: : Display the number of values and the maximum value using DOS services.
: : Comment on the limitations of your program.
: : the software i have to use is emu8086 http://www.emu8086.com/
: :
: : basically i have no clue where to start or what to do and never done any programming or used this software before, so anyone who knows a bit about programming and has used the software if you could give a few hints or anything i would be very grateful.
: :
:
: Please elabrate on your original post, and I will see what I can do.
:

:
:


by two decimal digits it means any number from 01 to 99
and by the maximum value it means the highest number i have put in.
So if i typed in 01, 34, 27, 85, 37, 67 i have to find a way of making it count how many numbers i had put in (6) and which was the highest value (85) and display that on the screen
Report
Re: emu8086 help Posted by MT2002 on 20 Jan 2007 at 9:25 PM
: : : Hi, im studying music and audio electronic systems in uni and i've been set an assingment for my microprocessor lecture. the assignment is:
: : :
: : : Write a program in (8088) assembly language that should be able to:
: : : Input any number of positive values of two decimal digits using DOS services.
: :
: : What do you mean by of two decimal digits? Do you mean two digits (ie, 23), floating point (ie 0.23), or two different numbers that require seperate inputs?
: :

: : : Find the maximum value.
: :
: : What do you mean here?
: :

: : : Display the number of values and the maximum value using DOS services.
: : : Comment on the limitations of your program.
: : : the software i have to use is emu8086 http://www.emu8086.com/
: : :
: : : basically i have no clue where to start or what to do and never done any programming or used this software before, so anyone who knows a bit about programming and has used the software if you could give a few hints or anything i would be very grateful.
: : :
: :
: : Please elabrate on your original post, and I will see what I can do.
: :

: :
: :
:
:
: by two decimal digits it means any number from 01 to 99
: and by the maximum value it means the highest number i have put in.
: So if i typed in 01, 34, 27, 85, 37, 67 i have to find a way of making it count how many numbers i had put in (6) and which was the highest value (85) and display that on the screen
:

You stated you never programmer before ...how do they expect you to build this program then? Unless x86 asm was a requirement for the course.

It would be quite hard to give hints to one whome never had exp with x86 asm. I personally recommend studying x86 asm a little to better undertand how it works.

I have built my own solution to your project (works with any number of input/displays max number, et al..) for Emu8086. If you would like the source (to study from), I can give you it. (Its not that hard).

If not, here is a "skeleton" program that will get you started...
data segment

  ; varables stored here..
ends  

stack segment     

    ; stack--do *not* modify this segment!
    dw   128  dup(0)
ends

code segment
start:
    mov     ax, data            ; setup registers
    mov     ds, ax
    mov     es, ax

;..your code here...

exit:    
    call    getch               ; wait for quit    
    mov     ax, 4c00h           ; return with error code 0
    int     21h                               

ends

;other procedures here..

end start ; set entry point and stop the assembler.


Hope this helps!



[/code]
Report
Re: emu8086 help Posted by super.rad on 21 Jan 2007 at 7:45 AM
: : : : Hi, im studying music and audio electronic systems in uni and i've been set an assingment for my microprocessor lecture. the assignment is:
: : : :
: : : : Write a program in (8088) assembly language that should be able to:
: : : : Input any number of positive values of two decimal digits using DOS services.
: : :
: : : What do you mean by of two decimal digits? Do you mean two digits (ie, 23), floating point (ie 0.23), or two different numbers that require seperate inputs?
: : :

: : : : Find the maximum value.
: : :
: : : What do you mean here?
: : :

: : : : Display the number of values and the maximum value using DOS services.
: : : : Comment on the limitations of your program.
: : : : the software i have to use is emu8086 http://www.emu8086.com/
: : : :
: : : : basically i have no clue where to start or what to do and never done any programming or used this software before, so anyone who knows a bit about programming and has used the software if you could give a few hints or anything i would be very grateful.
: : : :
: : :
: : : Please elabrate on your original post, and I will see what I can do.
: : :

: : :
: : :
: :
: :
: : by two decimal digits it means any number from 01 to 99
: : and by the maximum value it means the highest number i have put in.
: : So if i typed in 01, 34, 27, 85, 37, 67 i have to find a way of making it count how many numbers i had put in (6) and which was the highest value (85) and display that on the screen
: :
:
: You stated you never programmer before ...how do they expect you to build this program then? Unless x86 asm was a requirement for the course.
:
: It would be quite hard to give hints to one whome never had exp with x86 asm. I personally recommend studying x86 asm a little to better undertand how it works.
:
: I have built my own solution to your project (works with any number of input/displays max number, et al..) for Emu8086. If you would like the source (to study from), I can give you it. (Its not that hard).
:
: If not, here is a "skeleton" program that will get you started...
:
: data segment
: 
:   ; varables stored here..
: ends  
: 
: stack segment     
: 
:     ; stack--do *not* modify this segment!
:     dw   128  dup(0)
: ends
: 
: code segment
: start:
:     mov     ax, data            ; setup registers
:     mov     ds, ax
:     mov     es, ax
: 
: ;..your code here...
: 
: exit:    
:     call    getch               ; wait for quit    
:     mov     ax, 4c00h           ; return with error code 0
:     int     21h                               
: 
: ends
: 
: ;other procedures here..
: 
: end start ; set entry point and stop the assembler.
: 

:
: Hope this helps!

:
:
: [/code]
:
thanks a lot for your help, if you could paste the source code that would be brilliant as i can study over it to see how it works (it doesnt count as cheating as he said if we could find any code we could use it as long as we write comments about it and fully understand what it does and how it's doing it as the work is mainly marked on the write up. i know we were all a bit confused when he gave us this work as nobody knew how to program. Thanks again for all your help
Report
Re: emu8086 help Posted by MT2002 on 21 Jan 2007 at 12:31 PM
: : : : : Hi, im studying music and audio electronic systems in uni and i've been set an assingment for my microprocessor lecture. the assignment is:
: : : : :
: : : : : Write a program in (8088) assembly language that should be able to:
: : : : : Input any number of positive values of two decimal digits using DOS services.
: : : :
: : : : What do you mean by of two decimal digits? Do you mean two digits (ie, 23), floating point (ie 0.23), or two different numbers that require seperate inputs?
: : : :

: : : : : Find the maximum value.
: : : :
: : : : What do you mean here?
: : : :

: : : : : Display the number of values and the maximum value using DOS services.
: : : : : Comment on the limitations of your program.
: : : : : the software i have to use is emu8086 http://www.emu8086.com/
: : : : :
: : : : : basically i have no clue where to start or what to do and never done any programming or used this software before, so anyone who knows a bit about programming and has used the software if you could give a few hints or anything i would be very grateful.
: : : : :
: : : :
: : : : Please elabrate on your original post, and I will see what I can do.
: : : :

: : : :
: : : :
: : :
: : :
: : : by two decimal digits it means any number from 01 to 99
: : : and by the maximum value it means the highest number i have put in.
: : : So if i typed in 01, 34, 27, 85, 37, 67 i have to find a way of making it count how many numbers i had put in (6) and which was the highest value (85) and display that on the screen
: : :
: :
: : You stated you never programmer before ...how do they expect you to build this program then? Unless x86 asm was a requirement for the course.
: :
: : It would be quite hard to give hints to one whome never had exp with x86 asm. I personally recommend studying x86 asm a little to better undertand how it works.
: :
: : I have built my own solution to your project (works with any number of input/displays max number, et al..) for Emu8086. If you would like the source (to study from), I can give you it. (Its not that hard).
: :
: : If not, here is a "skeleton" program that will get you started...
: :
: : data segment
: : 
: :   ; varables stored here..
: : ends  
: : 
: : stack segment     
: : 
: :     ; stack--do *not* modify this segment!
: :     dw   128  dup(0)
: : ends
: : 
: : code segment
: : start:
: :     mov     ax, data            ; setup registers
: :     mov     ds, ax
: :     mov     es, ax
: : 
: : ;..your code here...
: : 
: : exit:    
: :     call    getch               ; wait for quit    
: :     mov     ax, 4c00h           ; return with error code 0
: :     int     21h                               
: : 
: : ends
: : 
: : ;other procedures here..
: : 
: : end start ; set entry point and stop the assembler.
: : 

: :
: : Hope this helps!

: :
: :
: : [/code]
: :
: thanks a lot for your help, if you could paste the source code that would be brilliant as i can study over it to see how it works (it doesnt count as cheating as he said if we could find any code we could use it as long as we write comments about it and fully understand what it does and how it's doing it as the work is mainly marked on the write up. i know we were all a bit confused when he gave us this work as nobody knew how to program. Thanks again for all your help
:

The program could be better (more effeciant, and cleaner), however it works.

Here is the program in action:
Please input a series of numbers. ->
32,12,09,90,32,54
Comparing numbers...
Number of numbers to compare:
6
The largest number is: 90

Press any key to exit...


It runs slow in Emu8086 emulater, however it runs nicely as a stand alone *.exe.

Heres the source (As I stated, it could be better)..
       
iNumInput equ 30                                                ; size of input buffers
                                             
data segment
    sInNum db "Please input a series of numbers. ->$"     
    sNum db "The largest number is: $"                 
    sInputs db "Number of numbers to compare: $"
    sCompare db "Comparing numbers...$"      
    sDone db "Press any key to exit...$"
    count dw 0                                                  ; storage for counting 
    numInts dw 0                                                ; number of ints input      
    integer dw 0                                                ; storage for integer        
    prevInt dw 0                                                ; previous integer for comparing 
    res     dw 0                                                ; result (largest interger)       
    inputBuf db iNumInput, ?, iNumInput dup ('$'), '$'          ; input buffer     
    numbrs dw iNumInput dub ('?')                               ; integer array   
ends  

stack segment     

    dw   128  dup(0)
ends


;******************************************
;
; Execution begins here
;
;******************************************

code segment
start:
    mov     ax, data            ; setup registers
    mov     ds, ax
    mov     es, ax            
    lea     dx, sInNum          ; print string to get input
    call    prntStr                   
    call    print_nl       
    lea     dx, inputBuf        ; get input
    call    scanStr      
    call    print_nl
    lea     dx, sCompare
    call    prntStr                                           
                
;--------------------------
; Convert chars to integers
;--------------------------
ascii:     
    pusha      
    lea     bx, inputBuf+2      ; actual start of buffer   
    xor     dx, dx
    mov     cx, 0               ; counter offset (index counter)       
      
loop1:                          ;..This would be better with loopze instruction..
    mov     dl, [bx]     
    inc     bx                  ; move to next char           
    cmp     dl, '$'             ; end of string?
    je      loop1end        
    cmp     dl, '0'             ; Insure character is valid
    je      prnt
    cmp     dl, '1'
    je      prnt
    cmp     dl, '2'
    je      prnt
    cmp     dl, '3'
    je      prnt              
    cmp     dl, '4'
    je      prnt
    cmp     dl, '5'
    je      prnt
    cmp     dl, '6'
    je      prnt      
    cmp     dl, '7'
    je      prnt
    cmp     dl, '8'
    je      prnt
    cmp     dl, '9'
    je      prnt                        
    ; not a valid number, so skip it
    jmp loop1
prnt:                         ; convert char to integer word
    sub     dl, 48            ; ASCII chars begin at decimal=48
    push    bx
    inc     cx
    lea     bx, numbrs
    add     bx, cx 
    mov     [bx], dl 
    pop     bx
    jmp     loop1                          
loop1end:      
    mov     [count], cx 
    popa

;-------------------------
; Perform actual computing
;-------------------------

compute:
    pusha  
    mov     dx, 0           ; current integer
    mov     cx, [count]     ; count=number of words in array     
    lea     bx, numbrs+1
            
loop2:                      ; ..would be better with loopze instruction..
  
;------------------------
; .Convert chars into workable integer
;------------------------
    dec     cx               ; no more chars?
    cmp     cx, 0
    je      loop2exit                               
    mov     ax, [bx]         ; get first digit      
    mov     dh, al           ; swap low order/high order words (integers stored in little-endian)
    mov     dl, ah
    mov     ax, dx            
    mov     [integer], dx   ; store our integer 
    mov     dl, 0             ; AH = tens place, AL=ones place (DX=AX)   
    mov     dh, 10                          
    mov     al, 0
    mul     dx               ; multiply by dx (DX=10 for tens place)
    mov     ax, dx           
    mov     dx, [integer]   ; now second digit (ones place)
    mov     dh, 0
    add     ax, dx           ; Add ones place
    mov     [integer], ax   ; integer = actual integeral value to compare

;-----------------------
; .Test for largest number
;-----------------------

    mov     dl, [loopTest]   ; test for first time looping                 
    cmp     dl, 0
    je      loop3first
    jmp     compare  
loop3first:                  
    mov     [prevInt], ax    ; first tme looping, so prevInt=curInt     
    mov     [res], ax
    mov     [loopTest], 1    ; set flag             
compare:         
    inc     [numInts]           ; ...one more integer         
    mov     dx, [integer]    ; is current int larger then previous?
    mov     ax, [prevInt]
    cmp     dx, ax     
    jge     greater   
    jmp     less   
greater:        
    ; ax is bigger, but bigger then res?
    mov     ax, dx
    mov     ax, [res]
    cmp     ax, dx
    jge     largest  
    mov     [res], dx       
    mov     [integer], ax    
    jmp     loop2end
largest:
    mov     [res], ax    ; yep--ax is largest       
    jmp     loop2end
less: 
    mov     [integer], dx  ; nope--dx must be largest  
 
;----------------------
; .Go to next char
;---------------------- 
loop2end:        
    mov     [prevInt], dx   ; store int to become next prev int                
    inc     bx           ; jump to next number (got to inc on word bonderies)
    inc     bx               
    jmp     loop2                            
loop2exit:    
    popa

;---------------------
; Print our answer
;---------------------
prntRes:         
    pusha   
    call    print_nl  
    lea     dx, sInputs
    call    prntStr
    call    print_nl 
    mov     ax, [numInts]  ; numInts contains number of digits for each char..   
    inc     ax       
    mov     bl, 02h        ;...because each int is 2 digits, we divide it (ignore overflow)
    div     bl
    call    print_ax  
    call    print_nl
    lea     dx, sNum
    call    prntStr   
    mov     ax, [res]
    call    print_ax   
    call    print_nl 
    call    print_nl
    lea     dx, sDone
    call    prntStr   
    popa

;-------------------------
; Exit back to OS
;-------------------------
exit:    
    call    getch               ; wait for quit    
    mov     ax, 4c00h           ; return with error code 0
    int     21h                               

ends  

 loopTest db  0 

;********************************
;
; Print integer as string (AX=integer)
;
;********************************  
print_ax proc
cmp ax, 0
jne print_ax_r
    push     ax
    mov     al, '0'
    mov     ah, 0eh
    int     10h
    pop      ax
    ret 
print_ax_r:
    pusha
    mov     dx, 0
    cmp     ax, 0
    je      pn_done
    mov     bx, 10
    div     bx    
    call    print_ax_r
    mov     ax, dx
    add     al, 30h
    mov     ah, 0eh
    int     10h    
    jmp     pn_done
pn_done:
    popa  
    ret  
print_ax endp

             
;*******************************************
;
; Prnt char (DL=char to print)
;
;*******************************************                  
prntChar proc near
    mov     ah, 02h
    int     21h 
    ret    
prntChar endp                  
  
                  
;*******************************************
;
; Prnt $-terminating string (DS:DX=>string)
;
;*******************************************              
prntStr proc near                          
    mov     ah, 9
    int     21h                              
    ret         
prntStr endp   
    
;*******************************************
;
; Prnt newline/CR
;
;*******************************************
print_nl proc 
    push    ax  
    push    dx  
    mov     ah, 2
    mov     dl, 0Dh
    int     21h  
    mov     dl, 0Ah
    int     21h   
    pop     dx 
    pop     ax      
    ret
print_nl endp    
    
                    
;*******************************************
;
;  Get input into buffer (DS:DX=>buffer)
;  First byte in buffer = number of chars to read
;  ret\ number of chars read stored in second byte in buffer
;
;*******************************************
scanStr proc    near 
   mov     ah, 0ah
   int     21h  
   ret      
scanStr endp

;*******************************************
;
; Wait for any key press
;
;*******************************************
getch proc near
    mov     ah, 1
    int     21h
    ret                               
getch endp                   
             
              
end start ; set entry point and stop the assembler.



Hope this helps;

~mt2002


Report
Re: emu8086 help Posted by super.rad on 21 Jan 2007 at 12:43 PM
: : : : : : Hi, im studying music and audio electronic systems in uni and i've been set an assingment for my microprocessor lecture. the assignment is:
: : : : : :
: : : : : : Write a program in (8088) assembly language that should be able to:
: : : : : : Input any number of positive values of two decimal digits using DOS services.
: : : : :
: : : : : What do you mean by of two decimal digits? Do you mean two digits (ie, 23), floating point (ie 0.23), or two different numbers that require seperate inputs?
: : : : :

: : : : : : Find the maximum value.
: : : : :
: : : : : What do you mean here?
: : : : :

: : : : : : Display the number of values and the maximum value using DOS services.
: : : : : : Comment on the limitations of your program.
: : : : : : the software i have to use is emu8086 http://www.emu8086.com/
: : : : : :
: : : : : : basically i have no clue where to start or what to do and never done any programming or used this software before, so anyone who knows a bit about programming and has used the software if you could give a few hints or anything i would be very grateful.
: : : : : :
: : : : :
: : : : : Please elabrate on your original post, and I will see what I can do.
: : : : :

: : : : :
: : : : :
: : : :
: : : :
: : : : by two decimal digits it means any number from 01 to 99
: : : : and by the maximum value it means the highest number i have put in.
: : : : So if i typed in 01, 34, 27, 85, 37, 67 i have to find a way of making it count how many numbers i had put in (6) and which was the highest value (85) and display that on the screen
: : : :
: : :
: : : You stated you never programmer before ...how do they expect you to build this program then? Unless x86 asm was a requirement for the course.
: : :
: : : It would be quite hard to give hints to one whome never had exp with x86 asm. I personally recommend studying x86 asm a little to better undertand how it works.
: : :
: : : I have built my own solution to your project (works with any number of input/displays max number, et al..) for Emu8086. If you would like the source (to study from), I can give you it. (Its not that hard).
: : :
: : : If not, here is a "skeleton" program that will get you started...
: : :
: : : data segment
: : : 
: : :   ; varables stored here..
: : : ends  
: : : 
: : : stack segment     
: : : 
: : :     ; stack--do *not* modify this segment!
: : :     dw   128  dup(0)
: : : ends
: : : 
: : : code segment
: : : start:
: : :     mov     ax, data            ; setup registers
: : :     mov     ds, ax
: : :     mov     es, ax
: : : 
: : : ;..your code here...
: : : 
: : : exit:    
: : :     call    getch               ; wait for quit    
: : :     mov     ax, 4c00h           ; return with error code 0
: : :     int     21h                               
: : : 
: : : ends
: : : 
: : : ;other procedures here..
: : : 
: : : end start ; set entry point and stop the assembler.
: : : 

: : :
: : : Hope this helps!

: : :
: : :
: : : [/code]
: : :
: : thanks a lot for your help, if you could paste the source code that would be brilliant as i can study over it to see how it works (it doesnt count as cheating as he said if we could find any code we could use it as long as we write comments about it and fully understand what it does and how it's doing it as the work is mainly marked on the write up. i know we were all a bit confused when he gave us this work as nobody knew how to program. Thanks again for all your help
: :
:
: The program could be better (more effeciant, and cleaner), however it works.
:
: Here is the program in action:
:
: Please input a series of numbers. ->
: 32,12,09,90,32,54
: Comparing numbers...
: Number of numbers to compare:
: 6
: The largest number is: 90
: 
: Press any key to exit...
: 

:
: It runs slow in Emu8086 emulater, however it runs nicely as a stand alone *.exe.
:
: Heres the source (As I stated, it could be better)..
:
       
: iNumInput equ 30                                                ; size of input buffers
:                                              
: data segment
:     sInNum db "Please input a series of numbers. ->$"     
:     sNum db "The largest number is: $"                 
:     sInputs db "Number of numbers to compare: $"
:     sCompare db "Comparing numbers...$"      
:     sDone db "Press any key to exit...$"
:     count dw 0                                                  ; storage for counting 
:     numInts dw 0                                                ; number of ints input      
:     integer dw 0                                                ; storage for integer        
:     prevInt dw 0                                                ; previous integer for comparing 
:     res     dw 0                                                ; result (largest interger)       
:     inputBuf db iNumInput, ?, iNumInput dup ('$'), '$'          ; input buffer     
:     numbrs dw iNumInput dub ('?')                               ; integer array   
: ends  
: 
: stack segment     
: 
:     dw   128  dup(0)
: ends
: 
: 
: ;******************************************
: ;
: ; Execution begins here
: ;
: ;******************************************
: 
: code segment
: start:
:     mov     ax, data            ; setup registers
:     mov     ds, ax
:     mov     es, ax            
:     lea     dx, sInNum          ; print string to get input
:     call    prntStr                   
:     call    print_nl       
:     lea     dx, inputBuf        ; get input
:     call    scanStr      
:     call    print_nl
:     lea     dx, sCompare
:     call    prntStr                                           
:                 
: ;--------------------------
: ; Convert chars to integers
: ;--------------------------
: ascii:     
:     pusha      
:     lea     bx, inputBuf+2      ; actual start of buffer   
:     xor     dx, dx
:     mov     cx, 0               ; counter offset (index counter)       
:       
: loop1:                          ;..This would be better with loopze instruction..
:     mov     dl, [bx]     
:     inc     bx                  ; move to next char           
:     cmp     dl, '$'             ; end of string?
:     je      loop1end        
:     cmp     dl, '0'             ; Insure character is valid
:     je      prnt
:     cmp     dl, '1'
:     je      prnt
:     cmp     dl, '2'
:     je      prnt
:     cmp     dl, '3'
:     je      prnt              
:     cmp     dl, '4'
:     je      prnt
:     cmp     dl, '5'
:     je      prnt
:     cmp     dl, '6'
:     je      prnt      
:     cmp     dl, '7'
:     je      prnt
:     cmp     dl, '8'
:     je      prnt
:     cmp     dl, '9'
:     je      prnt                        
:     ; not a valid number, so skip it
:     jmp loop1
: prnt:                         ; convert char to integer word
:     sub     dl, 48            ; ASCII chars begin at decimal=48
:     push    bx
:     inc     cx
:     lea     bx, numbrs
:     add     bx, cx 
:     mov     [bx], dl 
:     pop     bx
:     jmp     loop1                          
: loop1end:      
:     mov     [count], cx 
:     popa
: 
: ;-------------------------
: ; Perform actual computing
: ;-------------------------
: 
: compute:
:     pusha  
:     mov     dx, 0           ; current integer
:     mov     cx, [count]     ; count=number of words in array     
:     lea     bx, numbrs+1
:             
: loop2:                      ; ..would be better with loopze instruction..
:   
: ;------------------------
: ; .Convert chars into workable integer
: ;------------------------
:     dec     cx               ; no more chars?
:     cmp     cx, 0
:     je      loop2exit                               
:     mov     ax, [bx]         ; get first digit      
:     mov     dh, al           ; swap low order/high order words (integers stored in little-endian)
:     mov     dl, ah
:     mov     ax, dx            
:     mov     [integer], dx   ; store our integer 
:     mov     dl, 0             ; AH = tens place, AL=ones place (DX=AX)   
:     mov     dh, 10                          
:     mov     al, 0
:     mul     dx               ; multiply by dx (DX=10 for tens place)
:     mov     ax, dx           
:     mov     dx, [integer]   ; now second digit (ones place)
:     mov     dh, 0
:     add     ax, dx           ; Add ones place
:     mov     [integer], ax   ; integer = actual integeral value to compare
: 
: ;-----------------------
: ; .Test for largest number
: ;-----------------------
: 
:     mov     dl, [loopTest]   ; test for first time looping                 
:     cmp     dl, 0
:     je      loop3first
:     jmp     compare  
: loop3first:                  
:     mov     [prevInt], ax    ; first tme looping, so prevInt=curInt     
:     mov     [res], ax
:     mov     [loopTest], 1    ; set flag             
: compare:         
:     inc     [numInts]           ; ...one more integer         
:     mov     dx, [integer]    ; is current int larger then previous?
:     mov     ax, [prevInt]
:     cmp     dx, ax     
:     jge     greater   
:     jmp     less   
: greater:        
:     ; ax is bigger, but bigger then res?
:     mov     ax, dx
:     mov     ax, [res]
:     cmp     ax, dx
:     jge     largest  
:     mov     [res], dx       
:     mov     [integer], ax    
:     jmp     loop2end
: largest:
:     mov     [res], ax    ; yep--ax is largest       
:     jmp     loop2end
: less: 
:     mov     [integer], dx  ; nope--dx must be largest  
:  
: ;----------------------
: ; .Go to next char
: ;---------------------- 
: loop2end:        
:     mov     [prevInt], dx   ; store int to become next prev int                
:     inc     bx           ; jump to next number (got to inc on word bonderies)
:     inc     bx               
:     jmp     loop2                            
: loop2exit:    
:     popa
: 
: ;---------------------
: ; Print our answer
: ;---------------------
: prntRes:         
:     pusha   
:     call    print_nl  
:     lea     dx, sInputs
:     call    prntStr
:     call    print_nl 
:     mov     ax, [numInts]  ; numInts contains number of digits for each char..   
:     inc     ax       
:     mov     bl, 02h        ;...because each int is 2 digits, we divide it (ignore overflow)
:     div     bl
:     call    print_ax  
:     call    print_nl
:     lea     dx, sNum
:     call    prntStr   
:     mov     ax, [res]
:     call    print_ax   
:     call    print_nl 
:     call    print_nl
:     lea     dx, sDone
:     call    prntStr   
:     popa
: 
: ;-------------------------
: ; Exit back to OS
: ;-------------------------
: exit:    
:     call    getch               ; wait for quit    
:     mov     ax, 4c00h           ; return with error code 0
:     int     21h                               
: 
: ends  
: 
:  loopTest db  0 
: 
: ;********************************
: ;
: ; Print integer as string (AX=integer)
: ;
: ;********************************  
: print_ax proc
: cmp ax, 0
: jne print_ax_r
:     push     ax
:     mov     al, '0'
:     mov     ah, 0eh
:     int     10h
:     pop      ax
:     ret 
: print_ax_r:
:     pusha
:     mov     dx, 0
:     cmp     ax, 0
:     je      pn_done
:     mov     bx, 10
:     div     bx    
:     call    print_ax_r
:     mov     ax, dx
:     add     al, 30h
:     mov     ah, 0eh
:     int     10h    
:     jmp     pn_done
: pn_done:
:     popa  
:     ret  
: print_ax endp
: 
:              
: ;*******************************************
: ;
: ; Prnt char (DL=char to print)
: ;
: ;*******************************************                  
: prntChar proc near
:     mov     ah, 02h
:     int     21h 
:     ret    
: prntChar endp                  
:   
:                   
: ;*******************************************
: ;
: ; Prnt $-terminating string (DS:DX=>string)
: ;
: ;*******************************************              
: prntStr proc near                          
:     mov     ah, 9
:     int     21h                              
:     ret         
: prntStr endp   
:     
: ;*******************************************
: ;
: ; Prnt newline/CR
: ;
: ;*******************************************
: print_nl proc 
:     push    ax  
:     push    dx  
:     mov     ah, 2
:     mov     dl, 0Dh
:     int     21h  
:     mov     dl, 0Ah
:     int     21h   
:     pop     dx 
:     pop     ax      
:     ret
: print_nl endp    
:     
:                     
: ;*******************************************
: ;
: ;  Get input into buffer (DS:DX=>buffer)
: ;  First byte in buffer = number of chars to read
: ;  ret\ number of chars read stored in second byte in buffer
: ;
: ;*******************************************
: scanStr proc    near 
:    mov     ah, 0ah
:    int     21h  
:    ret      
: scanStr endp
: 
: ;*******************************************
: ;
: ; Wait for any key press
: ;
: ;*******************************************
: getch proc near
:     mov     ah, 1
:     int     21h
:     ret                               
: getch endp                   
:              
:               
: end start ; set entry point and stop the assembler.
: 
: 
: 

: Hope this helps;
:
: ~mt2002

:
:
thanks a lot this is great but only problem is when i click emulate in emu8086 i get this message
"file NOT built, there are errors!"
(0) No ENDS for: code
(204) ends unmatched!
(30) No ENDS for: stack
(21) ends unmatched!
(18) No ENDS for: data
(16) ends unmatched!
(3) No ENDS for: code

any ideas what these means and how i can sort them out? thanks a lot for all your help
Report
Re: emu8086 help Posted by MT2002 on 21 Jan 2007 at 1:16 PM
: : : : : : : Hi, im studying music and audio electronic systems in uni and i've been set an assingment for my microprocessor lecture. the assignment is:
: : : : : : :
: : : : : : : Write a program in (8088) assembly language that should be able to:
: : : : : : : Input any number of positive values of two decimal digits using DOS services.
: : : : : :
: : : : : : What do you mean by of two decimal digits? Do you mean two digits (ie, 23), floating point (ie 0.23), or two different numbers that require seperate inputs?
: : : : : :

: : : : : : : Find the maximum value.
: : : : : :
: : : : : : What do you mean here?
: : : : : :

: : : : : : : Display the number of values and the maximum value using DOS services.
: : : : : : : Comment on the limitations of your program.
: : : : : : : the software i have to use is emu8086 http://www.emu8086.com/
: : : : : : :
: : : : : : : basically i have no clue where to start or what to do and never done any programming or used this software before, so anyone who knows a bit about programming and has used the software if you could give a few hints or anything i would be very grateful.
: : : : : : :
: : : : : :
: : : : : : Please elabrate on your original post, and I will see what I can do.
: : : : : :

: : : : : :
: : : : : :
: : : : :
: : : : :
: : : : : by two decimal digits it means any number from 01 to 99
: : : : : and by the maximum value it means the highest number i have put in.
: : : : : So if i typed in 01, 34, 27, 85, 37, 67 i have to find a way of making it count how many numbers i had put in (6) and which was the highest value (85) and display that on the screen
: : : : :
: : : :
: : : : You stated you never programmer before ...how do they expect you to build this program then? Unless x86 asm was a requirement for the course.
: : : :
: : : : It would be quite hard to give hints to one whome never had exp with x86 asm. I personally recommend studying x86 asm a little to better undertand how it works.
: : : :
: : : : I have built my own solution to your project (works with any number of input/displays max number, et al..) for Emu8086. If you would like the source (to study from), I can give you it. (Its not that hard).
: : : :
: : : : If not, here is a "skeleton" program that will get you started...
: : : :
: : : : data segment
: : : : 
: : : :   ; varables stored here..
: : : : ends  
: : : : 
: : : : stack segment     
: : : : 
: : : :     ; stack--do *not* modify this segment!
: : : :     dw   128  dup(0)
: : : : ends
: : : : 
: : : : code segment
: : : : start:
: : : :     mov     ax, data            ; setup registers
: : : :     mov     ds, ax
: : : :     mov     es, ax
: : : : 
: : : : ;..your code here...
: : : : 
: : : : exit:    
: : : :     call    getch               ; wait for quit    
: : : :     mov     ax, 4c00h           ; return with error code 0
: : : :     int     21h                               
: : : : 
: : : : ends
: : : : 
: : : : ;other procedures here..
: : : : 
: : : : end start ; set entry point and stop the assembler.
: : : : 

: : : :
: : : : Hope this helps!

: : : :
: : : :
: : : : [/code]
: : : :
: : : thanks a lot for your help, if you could paste the source code that would be brilliant as i can study over it to see how it works (it doesnt count as cheating as he said if we could find any code we could use it as long as we write comments about it and fully understand what it does and how it's doing it as the work is mainly marked on the write up. i know we were all a bit confused when he gave us this work as nobody knew how to program. Thanks again for all your help
: : :
: :
: : The program could be better (more effeciant, and cleaner), however it works.
: :
: : Here is the program in action:
: :
: : Please input a series of numbers. ->
: : 32,12,09,90,32,54
: : Comparing numbers...
: : Number of numbers to compare:
: : 6
: : The largest number is: 90
: : 
: : Press any key to exit...
: : 

: :
: : It runs slow in Emu8086 emulater, however it runs nicely as a stand alone *.exe.
: :
: : Heres the source (As I stated, it could be better)..
: :
       
: : iNumInput equ 30                                                ; size of input buffers
: :                                              
: : data segment
: :     sInNum db "Please input a series of numbers. ->$"     
: :     sNum db "The largest number is: $"                 
: :     sInputs db "Number of numbers to compare: $"
: :     sCompare db "Comparing numbers...$"      
: :     sDone db "Press any key to exit...$"
: :     count dw 0                                                  ; storage for counting 
: :     numInts dw 0                                                ; number of ints input      
: :     integer dw 0                                                ; storage for integer        
: :     prevInt dw 0                                                ; previous integer for comparing 
: :     res     dw 0                                                ; result (largest interger)       
: :     inputBuf db iNumInput, ?, iNumInput dup ('$'), '$'          ; input buffer     
: :     numbrs dw iNumInput dub ('?')                               ; integer array   
: : ends  
: : 
: : stack segment     
: : 
: :     dw   128  dup(0)
: : ends
: : 
: : 
: : ;******************************************
: : ;
: : ; Execution begins here
: : ;
: : ;******************************************
: : 
: : code segment
: : start:
: :     mov     ax, data            ; setup registers
: :     mov     ds, ax
: :     mov     es, ax            
: :     lea     dx, sInNum          ; print string to get input
: :     call    prntStr                   
: :     call    print_nl       
: :     lea     dx, inputBuf        ; get input
: :     call    scanStr      
: :     call    print_nl
: :     lea     dx, sCompare
: :     call    prntStr                                           
: :                 
: : ;--------------------------
: : ; Convert chars to integers
: : ;--------------------------
: : ascii:     
: :     pusha      
: :     lea     bx, inputBuf+2      ; actual start of buffer   
: :     xor     dx, dx
: :     mov     cx, 0               ; counter offset (index counter)       
: :       
: : loop1:                          ;..This would be better with loopze instruction..
: :     mov     dl, [bx]     
: :     inc     bx                  ; move to next char           
: :     cmp     dl, '$'             ; end of string?
: :     je      loop1end        
: :     cmp     dl, '0'             ; Insure character is valid
: :     je      prnt
: :     cmp     dl, '1'
: :     je      prnt
: :     cmp     dl, '2'
: :     je      prnt
: :     cmp     dl, '3'
: :     je      prnt              
: :     cmp     dl, '4'
: :     je      prnt
: :     cmp     dl, '5'
: :     je      prnt
: :     cmp     dl, '6'
: :     je      prnt      
: :     cmp     dl, '7'
: :     je      prnt
: :     cmp     dl, '8'
: :     je      prnt
: :     cmp     dl, '9'
: :     je      prnt                        
: :     ; not a valid number, so skip it
: :     jmp loop1
: : prnt:                         ; convert char to integer word
: :     sub     dl, 48            ; ASCII chars begin at decimal=48
: :     push    bx
: :     inc     cx
: :     lea     bx, numbrs
: :     add     bx, cx 
: :     mov     [bx], dl 
: :     pop     bx
: :     jmp     loop1                          
: : loop1end:      
: :     mov     [count], cx 
: :     popa
: : 
: : ;-------------------------
: : ; Perform actual computing
: : ;-------------------------
: : 
: : compute:
: :     pusha  
: :     mov     dx, 0           ; current integer
: :     mov     cx, [count]     ; count=number of words in array     
: :     lea     bx, numbrs+1
: :             
: : loop2:                      ; ..would be better with loopze instruction..
: :   
: : ;------------------------
: : ; .Convert chars into workable integer
: : ;------------------------
: :     dec     cx               ; no more chars?
: :     cmp     cx, 0
: :     je      loop2exit                               
: :     mov     ax, [bx]         ; get first digit      
: :     mov     dh, al           ; swap low order/high order words (integers stored in little-endian)
: :     mov     dl, ah
: :     mov     ax, dx            
: :     mov     [integer], dx   ; store our integer 
: :     mov     dl, 0             ; AH = tens place, AL=ones place (DX=AX)   
: :     mov     dh, 10                          
: :     mov     al, 0
: :     mul     dx               ; multiply by dx (DX=10 for tens place)
: :     mov     ax, dx           
: :     mov     dx, [integer]   ; now second digit (ones place)
: :     mov     dh, 0
: :     add     ax, dx           ; Add ones place
: :     mov     [integer], ax   ; integer = actual integeral value to compare
: : 
: : ;-----------------------
: : ; .Test for largest number
: : ;-----------------------
: : 
: :     mov     dl, [loopTest]   ; test for first time looping                 
: :     cmp     dl, 0
: :     je      loop3first
: :     jmp     compare  
: : loop3first:                  
: :     mov     [prevInt], ax    ; first tme looping, so prevInt=curInt     
: :     mov     [res], ax
: :     mov     [loopTest], 1    ; set flag             
: : compare:         
: :     inc     [numInts]           ; ...one more integer         
: :     mov     dx, [integer]    ; is current int larger then previous?
: :     mov     ax, [prevInt]
: :     cmp     dx, ax     
: :     jge     greater   
: :     jmp     less   
: : greater:        
: :     ; ax is bigger, but bigger then res?
: :     mov     ax, dx
: :     mov     ax, [res]
: :     cmp     ax, dx
: :     jge     largest  
: :     mov     [res], dx       
: :     mov     [integer], ax    
: :     jmp     loop2end
: : largest:
: :     mov     [res], ax    ; yep--ax is largest       
: :     jmp     loop2end
: : less: 
: :     mov     [integer], dx  ; nope--dx must be largest  
: :  
: : ;----------------------
: : ; .Go to next char
: : ;---------------------- 
: : loop2end:        
: :     mov     [prevInt], dx   ; store int to become next prev int                
: :     inc     bx           ; jump to next number (got to inc on word bonderies)
: :     inc     bx               
: :     jmp     loop2                            
: : loop2exit:    
: :     popa
: : 
: : ;---------------------
: : ; Print our answer
: : ;---------------------
: : prntRes:         
: :     pusha   
: :     call    print_nl  
: :     lea     dx, sInputs
: :     call    prntStr
: :     call    print_nl 
: :     mov     ax, [numInts]  ; numInts contains number of digits for each char..   
: :     inc     ax       
: :     mov     bl, 02h        ;...because each int is 2 digits, we divide it (ignore overflow)
: :     div     bl
: :     call    print_ax  
: :     call    print_nl
: :     lea     dx, sNum
: :     call    prntStr   
: :     mov     ax, [res]
: :     call    print_ax   
: :     call    print_nl 
: :     call    print_nl
: :     lea     dx, sDone
: :     call    prntStr   
: :     popa
: : 
: : ;-------------------------
: : ; Exit back to OS
: : ;-------------------------
: : exit:    
: :     call    getch               ; wait for quit    
: :     mov     ax, 4c00h           ; return with error code 0
: :     int     21h                               
: : 
: : ends  
: : 
: :  loopTest db  0 
: : 
: : ;********************************
: : ;
: : ; Print integer as string (AX=integer)
: : ;
: : ;********************************  
: : print_ax proc
: : cmp ax, 0
: : jne print_ax_r
: :     push     ax
: :     mov     al, '0'
: :     mov     ah, 0eh
: :     int     10h
: :     pop      ax
: :     ret 
: : print_ax_r:
: :     pusha
: :     mov     dx, 0
: :     cmp     ax, 0
: :     je      pn_done
: :     mov     bx, 10
: :     div     bx    
: :     call    print_ax_r
: :     mov     ax, dx
: :     add     al, 30h
: :     mov     ah, 0eh
: :     int     10h    
: :     jmp     pn_done
: : pn_done:
: :     popa  
: :     ret  
: : print_ax endp
: : 
: :              
: : ;*******************************************
: : ;
: : ; Prnt char (DL=char to print)
: : ;
: : ;*******************************************                  
: : prntChar proc near
: :     mov     ah, 02h
: :     int     21h 
: :     ret    
: : prntChar endp                  
: :   
: :                   
: : ;*******************************************
: : ;
: : ; Prnt $-terminating string (DS:DX=>string)
: : ;
: : ;*******************************************              
: : prntStr proc near                          
: :     mov     ah, 9
: :     int     21h                              
: :     ret         
: : prntStr endp   
: :     
: : ;*******************************************
: : ;
: : ; Prnt newline/CR
: : ;
: : ;*******************************************
: : print_nl proc 
: :     push    ax  
: :     push    dx  
: :     mov     ah, 2
: :     mov     dl, 0Dh
: :     int     21h  
: :     mov     dl, 0Ah
: :     int     21h   
: :     pop     dx 
: :     pop     ax      
: :     ret
: : print_nl endp    
: :     
: :                     
: : ;*******************************************
: : ;
: : ;  Get input into buffer (DS:DX=>buffer)
: : ;  First byte in buffer = number of chars to read
: : ;  ret\ number of chars read stored in second byte in buffer
: : ;
: : ;*******************************************
: : scanStr proc    near 
: :    mov     ah, 0ah
: :    int     21h  
: :    ret      
: : scanStr endp
: : 
: : ;*******************************************
: : ;
: : ; Wait for any key press
: : ;
: : ;*******************************************
: : getch proc near
: :     mov     ah, 1
: :     int     21h
: :     ret                               
: : getch endp                   
: :              
: :               
: : end start ; set entry point and stop the assembler.
: : 
: : 
: : 

: : Hope this helps;
: :
: : ~mt2002

: :
: :
: thanks a lot this is great but only problem is when i click emulate in emu8086 i get this message
: "file NOT built, there are errors!"
: (0) No ENDS for: code
: (204) ends unmatched!
: (30) No ENDS for: stack
: (21) ends unmatched!
: (18) No ENDS for: data
: (16) ends unmatched!
: (3) No ENDS for: code
:
: any ideas what these means and how i can sort them out? thanks a lot for all your help
:

ends is a directive meaning "end segment". Multiple segments are primarily used with *.exe programs.

When creating a new project, in the "choose code template" dialog, Insure empty workspace is selected, and use flat assembler (fasm) synthax is not selected.

Everything should assemble fine.

Report
Re: emu8086 help Posted by super.rad on 21 Jan 2007 at 1:49 PM

: : : : :
: : : : : You stated you never programmer before ...how do they expect you to build this program then? Unless x86 asm was a requirement for the course.
: : : : :
: : : : : It would be quite hard to give hints to one whome never had exp with x86 asm. I personally recommend studying x86 asm a little to better undertand how it works.
: : : : :
: : : : : I have built my own solution to your project (works with any number of input/displays max number, et al..) for Emu8086. If you would like the source (to study from), I can give you it. (Its not that hard).
: : : : :
: : : : : If not, here is a "skeleton" program that will get you started...
: : : : :
: : : : : data segment
: : : : : 
: : : : :   ; varables stored here..
: : : : : ends  
: : : : : 
: : : : : stack segment     
: : : : : 
: : : : :     ; stack--do *not* modify this segment!
: : : : :     dw   128  dup(0)
: : : : : ends
: : : : : 
: : : : : code segment
: : : : : start:
: : : : :     mov     ax, data            ; setup registers
: : : : :     mov     ds, ax
: : : : :     mov     es, ax
: : : : : 
: : : : : ;..your code here...
: : : : : 
: : : : : exit:    
: : : : :     call    getch               ; wait for quit    
: : : : :     mov     ax, 4c00h           ; return with error code 0
: : : : :     int     21h                               
: : : : : 
: : : : : ends
: : : : : 
: : : : : ;other procedures here..
: : : : : 
: : : : : end start ; set entry point and stop the assembler.
: : : : : 

: : : : :
: : : : : Hope this helps!

: : : : :
: : : : :
: : : : : [/code]
: : : : :
: : : : thanks a lot for your help, if you could paste the source code that would be brilliant as i can study over it to see how it works (it doesnt count as cheating as he said if we could find any code we could use it as long as we write comments about it and fully understand what it does and how it's doing it as the work is mainly marked on the write up. i know we were all a bit confused when he gave us this work as nobody knew how to program. Thanks again for all your help
: : : :
: : :
: : : The program could be better (more effeciant, and cleaner), however it works.
: : :
: : : Here is the program in action:
: : :
: : : Please input a series of numbers. ->
: : : 32,12,09,90,32,54
: : : Comparing numbers...
: : : Number of numbers to compare:
: : : 6
: : : The largest number is: 90
: : : 
: : : Press any key to exit...
: : : 

: : :
: : : It runs slow in Emu8086 emulater, however it runs nicely as a stand alone *.exe.
: : :
: : : Heres the source (As I stated, it could be better)..
: : :
       
: : : iNumInput equ 30                                                ; size of input buffers
: : :                                              
: : : data segment
: : :     sInNum db "Please input a series of numbers. ->$"     
: : :     sNum db "The largest number is: $"                 
: : :     sInputs db "Number of numbers to compare: $"
: : :     sCompare db "Comparing numbers...$"      
: : :     sDone db "Press any key to exit...$"
: : :     count dw 0                                                  ; storage for counting 
: : :     numInts dw 0                                                ; number of ints input      
: : :     integer dw 0                                                ; storage for integer        
: : :     prevInt dw 0                                                ; previous integer for comparing 
: : :     res     dw 0                                                ; result (largest interger)       
: : :     inputBuf db iNumInput, ?, iNumInput dup ('$'), '$'          ; input buffer     
: : :     numbrs dw iNumInput dub ('?')                               ; integer array   
: : : ends  
: : : 
: : : stack segment     
: : : 
: : :     dw   128  dup(0)
: : : ends
: : : 
: : : 
: : : ;******************************************
: : : ;
: : : ; Execution begins here
: : : ;
: : : ;******************************************
: : : 
: : : code segment
: : : start:
: : :     mov     ax, data            ; setup registers
: : :     mov     ds, ax
: : :     mov     es, ax            
: : :     lea     dx, sInNum          ; print string to get input
: : :     call    prntStr                   
: : :     call    print_nl       
: : :     lea     dx, inputBuf        ; get input
: : :     call    scanStr      
: : :     call    print_nl
: : :     lea     dx, sCompare
: : :     call    prntStr                                           
: : :                 
: : : ;--------------------------
: : : ; Convert chars to integers
: : : ;--------------------------
: : : ascii:     
: : :     pusha      
: : :     lea     bx, inputBuf+2      ; actual start of buffer   
: : :     xor     dx, dx
: : :     mov     cx, 0               ; counter offset (index counter)       
: : :       
: : : loop1:                          ;..This would be better with loopze instruction..
: : :     mov     dl, [bx]     
: : :     inc     bx                  ; move to next char           
: : :     cmp     dl, '$'             ; end of string?
: : :     je      loop1end        
: : :     cmp     dl, '0'             ; Insure character is valid
: : :     je      prnt
: : :     cmp     dl, '1'
: : :     je      prnt
: : :     cmp     dl, '2'
: : :     je      prnt
: : :     cmp     dl, '3'
: : :     je      prnt              
: : :     cmp     dl, '4'
: : :     je      prnt
: : :     cmp     dl, '5'
: : :     je      prnt
: : :     cmp     dl, '6'
: : :     je      prnt      
: : :     cmp     dl, '7'
: : :     je      prnt
: : :     cmp     dl, '8'
: : :     je      prnt
: : :     cmp     dl, '9'
: : :     je      prnt                        
: : :     ; not a valid number, so skip it
: : :     jmp loop1
: : : prnt:                         ; convert char to integer word
: : :     sub     dl, 48            ; ASCII chars begin at decimal=48
: : :     push    bx
: : :     inc     cx
: : :     lea     bx, numbrs
: : :     add     bx, cx 
: : :     mov     [bx], dl 
: : :     pop     bx
: : :     jmp     loop1                          
: : : loop1end:      
: : :     mov     [count], cx 
: : :     popa
: : : 
: : : ;-------------------------
: : : ; Perform actual computing
: : : ;-------------------------
: : : 
: : : compute:
: : :     pusha  
: : :     mov     dx, 0           ; current integer
: : :     mov     cx, [count]     ; count=number of words in array     
: : :     lea     bx, numbrs+1
: : :             
: : : loop2:                      ; ..would be better with loopze instruction..
: : :   
: : : ;------------------------
: : : ; .Convert chars into workable integer
: : : ;------------------------
: : :     dec     cx               ; no more chars?
: : :     cmp     cx, 0
: : :     je      loop2exit                               
: : :     mov     ax, [bx]         ; get first digit      
: : :     mov     dh, al           ; swap low order/high order words (integers stored in little-endian)
: : :     mov     dl, ah
: : :     mov     ax, dx            
: : :     mov     [integer], dx   ; store our integer 
: : :     mov     dl, 0             ; AH = tens place, AL=ones place (DX=AX)   
: : :     mov     dh, 10                          
: : :     mov     al, 0
: : :     mul     dx               ; multiply by dx (DX=10 for tens place)
: : :     mov     ax, dx           
: : :     mov     dx, [integer]   ; now second digit (ones place)
: : :     mov     dh, 0
: : :     add     ax, dx           ; Add ones place
: : :     mov     [integer], ax   ; integer = actual integeral value to compare
: : : 
: : : ;-----------------------
: : : ; .Test for largest number
: : : ;-----------------------
: : : 
: : :     mov     dl, [loopTest]   ; test for first time looping                 
: : :     cmp     dl, 0
: : :     je      loop3first
: : :     jmp     compare  
: : : loop3first:                  
: : :     mov     [prevInt], ax    ; first tme looping, so prevInt=curInt     
: : :     mov     [res], ax
: : :     mov     [loopTest], 1    ; set flag             
: : : compare:         
: : :     inc     [numInts]           ; ...one more integer         
: : :     mov     dx, [integer]    ; is current int larger then previous?
: : :     mov     ax, [prevInt]
: : :     cmp     dx, ax     
: : :     jge     greater   
: : :     jmp     less   
: : : greater:        
: : :     ; ax is bigger, but bigger then res?
: : :     mov     ax, dx
: : :     mov     ax, [res]
: : :     cmp     ax, dx
: : :     jge     largest  
: : :     mov     [res], dx       
: : :     mov     [integer], ax    
: : :     jmp     loop2end
: : : largest:
: : :     mov     [res], ax    ; yep--ax is largest       
: : :     jmp     loop2end
: : : less: 
: : :     mov     [integer], dx  ; nope--dx must be largest  
: : :  
: : : ;----------------------
: : : ; .Go to next char
: : : ;---------------------- 
: : : loop2end:        
: : :     mov     [prevInt], dx   ; store int to become next prev int                
: : :     inc     bx           ; jump to next number (got to inc on word bonderies)
: : :     inc     bx               
: : :     jmp     loop2                            
: : : loop2exit:    
: : :     popa
: : : 
: : : ;---------------------
: : : ; Print our answer
: : : ;---------------------
: : : prntRes:         
: : :     pusha   
: : :     call    print_nl  
: : :     lea     dx, sInputs
: : :     call    prntStr
: : :     call    print_nl 
: : :     mov     ax, [numInts]  ; numInts contains number of digits for each char..   
: : :     inc     ax       
: : :     mov     bl, 02h        ;...because each int is 2 digits, we divide it (ignore overflow)
: : :     div     bl
: : :     call    print_ax  
: : :     call    print_nl
: : :     lea     dx, sNum
: : :     call    prntStr   
: : :     mov     ax, [res]
: : :     call    print_ax   
: : :     call    print_nl 
: : :     call    print_nl
: : :     lea     dx, sDone
: : :     call    prntStr   
: : :     popa
: : : 
: : : ;-------------------------
: : : ; Exit back to OS
: : : ;-------------------------
: : : exit:    
: : :     call    getch               ; wait for quit    
: : :     mov     ax, 4c00h           ; return with error code 0
: : :     int     21h                               
: : : 
: : : ends  
: : : 
: : :  loopTest db  0 
: : : 
: : : ;********************************
: : : ;
: : : ; Print integer as string (AX=integer)
: : : ;
: : : ;********************************  
: : : print_ax proc
: : : cmp ax, 0
: : : jne print_ax_r
: : :     push     ax
: : :     mov     al, '0'
: : :     mov     ah, 0eh
: : :     int     10h
: : :     pop      ax
: : :     ret 
: : : print_ax_r:
: : :     pusha
: : :     mov     dx, 0
: : :     cmp     ax, 0
: : :     je      pn_done
: : :     mov     bx, 10
: : :     div     bx    
: : :     call    print_ax_r
: : :     mov     ax, dx
: : :     add     al, 30h
: : :     mov     ah, 0eh
: : :     int     10h    
: : :     jmp     pn_done
: : : pn_done:
: : :     popa  
: : :     ret  
: : : print_ax endp
: : : 
: : :              
: : : ;*******************************************
: : : ;
: : : ; Prnt char (DL=char to print)
: : : ;
: : : ;*******************************************                  
: : : prntChar proc near
: : :     mov     ah, 02h
: : :     int     21h 
: : :     ret    
: : : prntChar endp                  
: : :   
: : :                   
: : : ;*******************************************
: : : ;
: : : ; Prnt $-terminating string (DS:DX=>string)
: : : ;
: : : ;*******************************************              
: : : prntStr proc near                          
: : :     mov     ah, 9
: : :     int     21h                              
: : :     ret         
: : : prntStr endp   
: : :     
: : : ;*******************************************
: : : ;
: : : ; Prnt newline/CR
: : : ;
: : : ;*******************************************
: : : print_nl proc 
: : :     push    ax  
: : :     push    dx  
: : :     mov     ah, 2
: : :     mov     dl, 0Dh
: : :     int     21h  
: : :     mov     dl, 0Ah
: : :     int     21h   
: : :     pop     dx 
: : :     pop     ax      
: : :     ret
: : : print_nl endp    
: : :     
: : :                     
: : : ;*******************************************
: : : ;
: : : ;  Get input into buffer (DS:DX=>buffer)
: : : ;  First byte in buffer = number of chars to read
: : : ;  ret\ number of chars read stored in second byte in buffer
: : : ;
: : : ;*******************************************
: : : scanStr proc    near 
: : :    mov     ah, 0ah
: : :    int     21h  
: : :    ret      
: : : scanStr endp
: : : 
: : : ;*******************************************
: : : ;
: : : ; Wait for any key press
: : : ;
: : : ;*******************************************
: : : getch proc near
: : :     mov     ah, 1
: : :     int     21h
: : :     ret                               
: : : getch endp                   
: : :              
: : :               
: : : end start ; set entry point and stop the assembler.
: : : 
: : : 
: : : 

: : : Hope this helps;
: : :
: : : ~mt2002

: : :
: : :
: : thanks a lot this is great but only problem is when i click emulate in emu8086 i get this message
: : "file NOT built, there are errors!"
: : (0) No ENDS for: code
: : (204) ends unmatched!
: : (30) No ENDS for: stack
: : (21) ends unmatched!
: : (18) No ENDS for: data
: : (16) ends unmatched!
: : (3) No ENDS for: code
: :
: : any ideas what these means and how i can sort them out? thanks a lot for all your help
: :
:
: ends is a directive meaning "end segment". Multiple segments are primarily used with *.exe programs.
:
: When creating a new project, in the "choose code template" dialog, Insure empty workspace is selected, and use flat assembler (fasm) synthax is not selected.
:
: Everything should assemble fine.
:

:
i have version 3.07 and theirs no option for empty workspace, when you click new you either have COM template, EXE template, BIN template, BOOT template. Also where is the option for "use flat assembler (fasm) synthax?
Report
Re: emu8086 help Posted by MT2002 on 21 Jan 2007 at 1:56 PM
This message was edited by MT2002 at 2007-1-21 13:58:40

:
: : : : : :
: : : : : : You stated you never programmer before ...how do they expect you to build this program then? Unless x86 asm was a requirement for the course.
: : : : : :
: : : : : : It would be quite hard to give hints to one whome never had exp with x86 asm. I personally recommend studying x86 asm a little to better undertand how it works.
: : : : : :
: : : : : : I have built my own solution to your project (works with any number of input/displays max number, et al..) for Emu8086. If you would like the source (to study from), I can give you it. (Its not that hard).
: : : : : :
: : : : : : If not, here is a "skeleton" program that will get you started...
: : : : : :
: : : : : : data segment
: : : : : : 
: : : : : :   ; varables stored here..
: : : : : : ends  
: : : : : : 
: : : : : : stack segment     
: : : : : : 
: : : : : :     ; stack--do *not* modify this segment!
: : : : : :     dw   128  dup(0)
: : : : : : ends
: : : : : : 
: : : : : : code segment
: : : : : : start:
: : : : : :     mov     ax, data            ; setup registers
: : : : : :     mov     ds, ax
: : : : : :     mov     es, ax
: : : : : : 
: : : : : : ;..your code here...
: : : : : : 
: : : : : : exit:    
: : : : : :     call    getch               ; wait for quit    
: : : : : :     mov     ax, 4c00h           ; return with error code 0
: : : : : :     int     21h                               
: : : : : : 
: : : : : : ends
: : : : : : 
: : : : : : ;other procedures here..
: : : : : : 
: : : : : : end start ; set entry point and stop the assembler.
: : : : : : 

: : : : : :
: : : : : : Hope this helps!

: : : : : :
: : : : : :
: : : : : : [/code]
: : : : : :
: : : : : thanks a lot for your help, if you could paste the source code that would be brilliant as i can study over it to see how it works (it doesnt count as cheating as he said if we could find any code we could use it as long as we write comments about it and fully understand what it does and how it's doing it as the work is mainly marked on the write up. i know we were all a bit confused when he gave us this work as nobody knew how to program. Thanks again for all your help
: : : : :
: : : :
: : : : The program could be better (more effeciant, and cleaner), however it works.
: : : :
: : : : Here is the program in action:
: : : :
: : : : Please input a series of numbers. ->
: : : : 32,12,09,90,32,54
: : : : Comparing numbers...
: : : : Number of numbers to compare:
: : : : 6
: : : : The largest number is: 90
: : : : 
: : : : Press any key to exit...
: : : : 

: : : :
: : : : It runs slow in Emu8086 emulater, however it runs nicely as a stand alone *.exe.
: : : :
: : : : Heres the source (As I stated, it could be better)..
: : : :
       
: : : : iNumInput equ 30                                                ; size of input buffers
: : : :                                              
: : : : data segment
: : : :     sInNum db "Please input a series of numbers. ->$"     
: : : :     sNum db "The largest number is: $"                 
: : : :     sInputs db "Number of numbers to compare: $"
: : : :     sCompare db "Comparing numbers...$"      
: : : :     sDone db "Press any key to exit...$"
: : : :     count dw 0                                                  ; storage for counting 
: : : :     numInts dw 0                                                ; number of ints input      
: : : :     integer dw 0                                                ; storage for integer        
: : : :     prevInt dw 0                                                ; previous integer for comparing 
: : : :     res     dw 0                                                ; result (largest interger)       
: : : :     inputBuf db iNumInput, ?, iNumInput dup ('$'), '$'          ; input buffer     
: : : :     numbrs dw iNumInput dub ('?')                               ; integer array   
: : : : ends  
: : : : 
: : : : stack segment     
: : : : 
: : : :     dw   128  dup(0)
: : : : ends
: : : : 
: : : : 
: : : : ;******************************************
: : : : ;
: : : : ; Execution begins here
: : : : ;
: : : : ;******************************************
: : : : 
: : : : code segment
: : : : start:
: : : :     mov     ax, data            ; setup registers
: : : :     mov     ds, ax
: : : :     mov     es, ax            
: : : :     lea     dx, sInNum          ; print string to get input
: : : :     call    prntStr                   
: : : :     call    print_nl       
: : : :     lea     dx, inputBuf        ; get input
: : : :     call    scanStr      
: : : :     call    print_nl
: : : :     lea     dx, sCompare
: : : :     call    prntStr                                           
: : : :                 
: : : : ;--------------------------
: : : : ; Convert chars to integers
: : : : ;--------------------------
: : : : ascii:     
: : : :     pusha      
: : : :     lea     bx, inputBuf+2      ; actual start of buffer   
: : : :     xor     dx, dx
: : : :     mov     cx, 0               ; counter offset (index counter)       
: : : :       
: : : : loop1:                          ;..This would be better with loopze instruction..
: : : :     mov     dl, [bx]     
: : : :     inc     bx                  ; move to next char           
: : : :     cmp     dl, '$'             ; end of string?
: : : :     je      loop1end        
: : : :     cmp     dl, '0'             ; Insure character is valid
: : : :     je      prnt
: : : :     cmp     dl, '1'
: : : :     je      prnt
: : : :     cmp     dl, '2'
: : : :     je      prnt
: : : :     cmp     dl, '3'
: : : :     je      prnt              
: : : :     cmp     dl, '4'
: : : :     je      prnt
: : : :     cmp     dl, '5'
: : : :     je      prnt
: : : :     cmp     dl, '6'
: : : :     je      prnt      
: : : :     cmp     dl, '7'
: : : :     je      prnt
: : : :     cmp     dl, '8'
: : : :     je      prnt
: : : :     cmp     dl, '9'
: : : :     je      prnt                        
: : : :     ; not a valid number, so skip it
: : : :     jmp loop1
: : : : prnt:                         ; convert char to integer word
: : : :     sub     dl, 48            ; ASCII chars begin at decimal=48
: : : :     push    bx
: : : :     inc     cx
: : : :     lea     bx, numbrs
: : : :     add     bx, cx 
: : : :     mov     [bx], dl 
: : : :     pop     bx
: : : :     jmp     loop1                          
: : : : loop1end:      
: : : :     mov     [count], cx 
: : : :     popa
: : : : 
: : : : ;-------------------------
: : : : ; Perform actual computing
: : : : ;-------------------------
: : : : 
: : : : compute:
: : : :     pusha  
: : : :     mov     dx, 0           ; current integer
: : : :     mov     cx, [count]     ; count=number of words in array     
: : : :     lea     bx, numbrs+1
: : : :             
: : : : loop2:                      ; ..would be better with loopze instruction..
: : : :   
: : : : ;------------------------
: : : : ; .Convert chars into workable integer
: : : : ;------------------------
: : : :     dec     cx               ; no more chars?
: : : :     cmp     cx, 0
: : : :     je      loop2exit                               
: : : :     mov     ax, [bx]         ; get first digit      
: : : :     mov     dh, al           ; swap low order/high order words (integers stored in little-endian)
: : : :     mov     dl, ah
: : : :     mov     ax, dx            
: : : :     mov     [integer], dx   ; store our integer 
: : : :     mov     dl, 0             ; AH = tens place, AL=ones place (DX=AX)   
: : : :     mov     dh, 10                          
: : : :     mov     al, 0
: : : :     mul     dx               ; multiply by dx (DX=10 for tens place)
: : : :     mov     ax, dx           
: : : :     mov     dx, [integer]   ; now second digit (ones place)
: : : :     mov     dh, 0
: : : :     add     ax, dx           ; Add ones place
: : : :     mov     [integer], ax   ; integer = actual integeral value to compare
: : : : 
: : : : ;-----------------------
: : : : ; .Test for largest number
: : : : ;-----------------------
: : : : 
: : : :     mov     dl, [loopTest]   ; test for first time looping                 
: : : :     cmp     dl, 0
: : : :     je      loop3first
: : : :     jmp     compare  
: : : : loop3first:                  
: : : :     mov     [prevInt], ax    ; first tme looping, so prevInt=curInt     
: : : :     mov     [res], ax
: : : :     mov     [loopTest], 1    ; set flag             
: : : : compare:         
: : : :     inc     [numInts]           ; ...one more integer         
: : : :     mov     dx, [integer]    ; is current int larger then previous?
: : : :     mov     ax, [prevInt]
: : : :     cmp     dx, ax     
: : : :     jge     greater   
: : : :     jmp     less   
: : : : greater:        
: : : :     ; ax is bigger, but bigger then res?
: : : :     mov     ax, dx
: : : :     mov     ax, [res]
: : : :     cmp     ax, dx
: : : :     jge     largest  
: : : :     mov     [res], dx       
: : : :     mov     [integer], ax    
: : : :     jmp     loop2end
: : : : largest:
: : : :     mov     [res], ax    ; yep--ax is largest       
: : : :     jmp     loop2end
: : : : less: 
: : : :     mov     [integer], dx  ; nope--dx must be largest  
: : : :  
: : : : ;----------------------
: : : : ; .Go to next char
: : : : ;---------------------- 
: : : : loop2end:        
: : : :     mov     [prevInt], dx   ; store int to become next prev int                
: : : :     inc     bx           ; jump to next number (got to inc on word bonderies)
: : : :     inc     bx               
: : : :     jmp     loop2                            
: : : : loop2exit:    
: : : :     popa
: : : : 
: : : : ;---------------------
: : : : ; Print our answer
: : : : ;---------------------
: : : : prntRes:         
: : : :     pusha   
: : : :     call    print_nl  
: : : :     lea     dx, sInputs
: : : :     call    prntStr
: : : :     call    print_nl 
: : : :     mov     ax, [numInts]  ; numInts contains number of digits for each char..   
: : : :     inc     ax       
: : : :     mov     bl, 02h        ;...because each int is 2 digits, we divide it (ignore overflow)
: : : :     div     bl
: : : :     call    print_ax  
: : : :     call    print_nl
: : : :     lea     dx, sNum
: : : :     call    prntStr   
: : : :     mov     ax, [res]
: : : :     call    print_ax   
: : : :     call    print_nl 
: : : :     call    print_nl
: : : :     lea     dx, sDone
: : : :     call    prntStr   
: : : :     popa
: : : : 
: : : : ;-------------------------
: : : : ; Exit back to OS
: : : : ;-------------------------
: : : : exit:    
: : : :     call    getch               ; wait for quit    
: : : :     mov     ax, 4c00h           ; return with error code 0
: : : :     int     21h                               
: : : : 
: : : : ends  
: : : : 
: : : :  loopTest db  0 
: : : : 
: : : : ;********************************
: : : : ;
: : : : ; Print integer as string (AX=integer)
: : : : ;
: : : : ;********************************  
: : : : print_ax proc
: : : : cmp ax, 0
: : : : jne print_ax_r
: : : :     push     ax
: : : :     mov     al, '0'
: : : :     mov     ah, 0eh
: : : :     int     10h
: : : :     pop      ax
: : : :     ret 
: : : : print_ax_r:
: : : :     pusha
: : : :     mov     dx, 0
: : : :     cmp     ax, 0
: : : :     je      pn_done
: : : :     mov     bx, 10
: : : :     div     bx    
: : : :     call    print_ax_r
: : : :     mov     ax, dx
: : : :     add     al, 30h
: : : :     mov     ah, 0eh
: : : :     int     10h    
: : : :     jmp     pn_done
: : : : pn_done:
: : : :     popa  
: : : :     ret  
: : : : print_ax endp
: : : : 
: : : :              
: : : : ;*******************************************
: : : : ;
: : : : ; Prnt char (DL=char to print)
: : : : ;
: : : : ;*******************************************                  
: : : : prntChar proc near
: : : :     mov     ah, 02h
: : : :     int     21h 
: : : :     ret    
: : : : prntChar endp                  
: : : :   
: : : :                   
: : : : ;*******************************************
: : : : ;
: : : : ; Prnt $-terminating string (DS:DX=>string)
: : : : ;
: : : : ;*******************************************              
: : : : prntStr proc near                          
: : : :     mov     ah, 9
: : : :     int     21h                              
: : : :     ret         
: : : : prntStr endp   
: : : :     
: : : : ;*******************************************
: : : : ;
: : : : ; Prnt newline/CR
: : : : ;
: : : : ;*******************************************
: : : : print_nl proc 
: : : :     push    ax  
: : : :     push    dx  
: : : :     mov     ah, 2
: : : :     mov     dl, 0Dh
: : : :     int     21h  
: : : :     mov     dl, 0Ah
: : : :     int     21h   
: : : :     pop     dx 
: : : :     pop     ax      
: : : :     ret
: : : : print_nl endp    
: : : :     
: : : :                     
: : : : ;*******************************************
: : : : ;
: : : : ;  Get input into buffer (DS:DX=>buffer)
: : : : ;  First byte in buffer = number of chars to read
: : : : ;  ret\ number of chars read stored in second byte in buffer
: : : : ;
: : : : ;*******************************************
: : : : scanStr proc    near 
: : : :    mov     ah, 0ah
: : : :    int     21h  
: : : :    ret      
: : : : scanStr endp
: : : : 
: : : : ;*******************************************
: : : : ;
: : : : ; Wait for any key press
: : : : ;
: : : : ;*******************************************
: : : : getch proc near
: : : :     mov     ah, 1
: : : :     int     21h
: : : :     ret                               
: : : : getch endp                   
: : : :              
: : : :               
: : : : end start ; set entry point and stop the assembler.
: : : : 
: : : : 
: : : : 

: : : : Hope this helps;
: : : :
: : : : ~mt2002

: : : :
: : : :
: : : thanks a lot this is great but only problem is when i click emulate in emu8086 i get this message
: : : "file NOT built, there are errors!"
: : : (0) No ENDS for: code
: : : (204) ends unmatched!
: : : (30) No ENDS for: stack
: : : (21) ends unmatched!
: : : (18) No ENDS for: data
: : : (16) ends unmatched!
: : : (3) No ENDS for: code
: : :
: : : any ideas what these means and how i can sort them out? thanks a lot for all your help
: : :
: :
: : ends is a directive meaning "end segment". Multiple segments are primarily used with *.exe programs.
: :
: : When creating a new project, in the "choose code template" dialog, Insure empty workspace is selected, and use flat assembler (fasm) synthax is not selected.
: :
: : Everything should assemble fine.
: :

: :
: i have version 3.07 and theirs no option for empty workspace, when you click new you either have COM template, EXE template, BIN template, BOOT template. Also where is the option for "use flat assembler (fasm) synthax?
:

Select "Use EXE template". If Emu8086 generates code, delete the code and copy mine.

*edit:
ProgrammersHeaven only allows posts nested 10 times, so if you still need help, and are unable to post, feel free to either edit this post, or reply to an earilier post.



Report
Re: emu8086 help Posted by super.rad on 21 Jan 2007 at 2:09 PM

: : : : : : : [/blue]
: : : : : : : data segment
: : : : : : : 
: : : : : : :   ; varables stored here..
: : : : : : : ends  
: : : : : : : 
: : : : : : : stack segment     
: : : : : : : 
: : : : : : :     ; stack--do *not* modify this segment!
: : : : : : :     dw   128  dup(0)
: : : : : : : ends
: : : : : : : 
: : : : : : : code segment
: : : : : : : start:
: : : : : : :     mov     ax, data            ; setup registers
: : : : : : :     mov     ds, ax
: : : : : : :     mov     es, ax
: : : : : : : 
: : : : : : : ;..your code here...
: : : : : : : 
: : : : : : : exit:    
: : : : : : :     call    getch               ; wait for quit    
: : : : : : :     mov     ax, 4c00h           ; return with error code 0
: : : : : : :     int     21h                               
: : : : : : : 
: : : : : : : ends
: : : : : : : 
: : : : : : : ;other procedures here..
: : : : : : : 
: : : : : : : end start ; set entry point and stop the assembler.
: : : : : : : 

: : : : : : :
: : : : : : : Hope this helps!

: : : : : : :
: : : : : : :
: : : : : : : [/code]
: : : : : : :

: : : : : :
: : : : :
: : : : : The program could be better (more effeciant, and cleaner), however it works.
: : : : :
: : : : : Here is the program in action:
: : : : :
: : : : : Please input a series of numbers. ->
: : : : : 32,12,09,90,32,54
: : : : : Comparing numbers...
: : : : : Number of numbers to compare:
: : : : : 6
: : : : : The largest number is: 90
: : : : : 
: : : : : Press any key to exit...
: : : : : 

: : : : :
: : : : : It runs slow in Emu8086 emulater, however it runs nicely as a stand alone *.exe.
: : : : :
: : : : : Heres the source (As I stated, it could be better)..
: : : : :
       
: : : : : iNumInput equ 30                                                ; size of input buffers
: : : : :                                              
: : : : : data segment
: : : : :     sInNum db "Please input a series of numbers. ->$"     
: : : : :     sNum db "The largest number is: $"                 
: : : : :     sInputs db "Number of numbers to compare: $"
: : : : :     sCompare db "Comparing numbers...$"      
: : : : :     sDone db "Press any key to exit...$"
: : : : :     count dw 0                                                  ; storage for counting 
: : : : :     numInts dw 0                                                ; number of ints input      
: : : : :     integer dw 0                                                ; storage for integer        
: : : : :     prevInt dw 0                                                ; previous integer for comparing 
: : : : :     res     dw 0                                                ; result (largest interger)       
: : : : :     inputBuf db iNumInput, ?, iNumInput dup ('$'), '$'          ; input buffer     
: : : : :     numbrs dw iNumInput dub ('?')                               ; integer array   
: : : : : ends  
: : : : : 
: : : : : stack segment     
: : : : : 
: : : : :     dw   128  dup(0)
: : : : : ends
: : : : : 
: : : : : 
: : : : : ;******************************************
: : : : : ;
: : : : : ; Execution begins here
: : : : : ;
: : : : : ;******************************************
: : : : : 
: : : : : code segment
: : : : : start:
: : : : :     mov     ax, data            ; setup registers
: : : : :     mov     ds, ax
: : : : :     mov     es, ax            
: : : : :     lea     dx, sInNum          ; print string to get input
: : : : :     call    prntStr                   
: : : : :     call    print_nl       
: : : : :     lea     dx, inputBuf        ; get input
: : : : :     call    scanStr      
: : : : :     call    print_nl
: : : : :     lea     dx, sCompare
: : : : :     call    prntStr                                           
: : : : :                 
: : : : : ;--------------------------
: : : : : ; Convert chars to integers
: : : : : ;--------------------------
: : : : : ascii:     
: : : : :     pusha      
: : : : :     lea     bx, inputBuf+2      ; actual start of buffer   
: : : : :     xor     dx, dx
: : : : :     mov     cx, 0               ; counter offset (index counter)       
: : : : :       
: : : : : loop1:                          ;..This would be better with loopze instruction..
: : : : :     mov     dl, [bx]     
: : : : :     inc     bx                  ; move to next char           
: : : : :     cmp     dl, '$'             ; end of string?
: : : : :     je      loop1end        
: : : : :     cmp     dl, '0'             ; Insure character is valid
: : : : :     je      prnt
: : : : :     cmp     dl, '1'
: : : : :     je      prnt
: : : : :     cmp     dl, '2'
: : : : :     je      prnt
: : : : :     cmp     dl, '3'
: : : : :     je      prnt              
: : : : :     cmp     dl, '4'
: : : : :     je      prnt
: : : : :     cmp     dl, '5'
: : : : :     je      prnt
: : : : :     cmp     dl, '6'
: : : : :     je      prnt      
: : : : :     cmp     dl, '7'
: : : : :     je      prnt
: : : : :     cmp     dl, '8'
: : : : :     je      prnt
: : : : :     cmp     dl, '9'
: : : : :     je      prnt                        
: : : : :     ; not a valid number, so skip it
: : : : :     jmp loop1
: : : : : prnt:                         ; convert char to integer word
: : : : :     sub     dl, 48            ; ASCII chars begin at decimal=48
: : : : :     push    bx
: : : : :     inc     cx
: : : : :     lea     bx, numbrs
: : : : :     add     bx, cx 
: : : : :     mov     [bx], dl 
: : : : :     pop     bx
: : : : :     jmp     loop1                          
: : : : : loop1end:      
: : : : :     mov     [count], cx 
: : : : :     popa
: : : : : 
: : : : : ;-------------------------
: : : : : ; Perform actual computing
: : : : : ;-------------------------
: : : : : 
: : : : : compute:
: : : : :     pusha  
: : : : :     mov     dx, 0           ; current integer
: : : : :     mov     cx, [count]     ; count=number of words in array     
: : : : :     lea     bx, numbrs+1
: : : : :             
: : : : : loop2:                      ; ..would be better with loopze instruction..
: : : : :   
: : : : : ;------------------------
: : : : : ; .Convert chars into workable integer
: : : : : ;------------------------
: : : : :     dec     cx               ; no more chars?
: : : : :     cmp     cx, 0
: : : : :     je      loop2exit                               
: : : : :     mov     ax, [bx]         ; get first digit      
: : : : :     mov     dh, al           ; swap low order/high order words (integers stored in little-endian)
: : : : :     mov     dl, ah
: : : : :     mov     ax, dx            
: : : : :     mov     [integer], dx   ; store our integer 
: : : : :     mov     dl, 0             ; AH = tens place, AL=ones place (DX=AX)   
: : : : :     mov     dh, 10                          
: : : : :     mov     al, 0
: : : : :     mul     dx               ; multiply by dx (DX=10 for tens place)
: : : : :     mov     ax, dx           
: : : : :     mov     dx, [integer]   ; now second digit (ones place)
: : : : :     mov     dh, 0
: : : : :     add     ax, dx           ; Add ones place
: : : : :     mov     [integer], ax   ; integer = actual integeral value to compare
: : : : : 
: : : : : ;-----------------------
: : : : : ; .Test for largest number
: : : : : ;-----------------------
: : : : : 
: : : : :     mov     dl, [loopTest]   ; test for first time looping                 
: : : : :     cmp     dl, 0
: : : : :     je      loop3first
: : : : :     jmp     compare  
: : : : : loop3first:                  
: : : : :     mov     [prevInt], ax    ; first tme looping, so prevInt=curInt     
: : : : :     mov     [res], ax
: : : : :     mov     [loopTest], 1    ; set flag             
: : : : : compare:         
: : : : :     inc     [numInts]           ; ...one more integer         
: : : : :     mov     dx, [integer]    ; is current int larger then previous?
: : : : :     mov     ax, [prevInt]
: : : : :     cmp     dx, ax     
: : : : :     jge     greater   
: : : : :     jmp     less   
: : : : : greater:        
: : : : :     ; ax is bigger, but bigger then res?
: : : : :     mov     ax, dx
: : : : :     mov     ax, [res]
: : : : :     cmp     ax, dx
: : : : :     jge     largest  
: : : : :     mov     [res], dx       
: : : : :     mov     [integer], ax    
: : : : :     jmp     loop2end
: : : : : largest:
: : : : :     mov     [res], ax    ; yep--ax is largest       
: : : : :     jmp     loop2end
: : : : : less: 
: : : : :     mov     [integer], dx  ; nope--dx must be largest  
: : : : :  
: : : : : ;----------------------
: : : : : ; .Go to next char
: : : : : ;---------------------- 
: : : : : loop2end:        
: : : : :     mov     [prevInt], dx   ; store int to become next prev int                
: : : : :     inc     bx           ; jump to next number (got to inc on word bonderies)
: : : : :     inc     bx               
: : : : :     jmp     loop2                            
: : : : : loop2exit:    
: : : : :     popa
: : : : : 
: : : : : ;---------------------
: : : : : ; Print our answer
: : : : : ;---------------------
: : : : : prntRes:         
: : : : :     pusha   
: : : : :     call    print_nl  
: : : : :     lea     dx, sInputs
: : : : :     call    prntStr
: : : : :     call    print_nl 
: : : : :     mov     ax, [numInts]  ; numInts contains number of digits for each char..   
: : : : :     inc     ax       
: : : : :     mov     bl, 02h        ;...because each int is 2 digits, we divide it (ignore overflow)
: : : : :     div     bl
: : : : :     call    print_ax  
: : : : :     call    print_nl
: : : : :     lea     dx, sNum
: : : : :     call    prntStr   
: : : : :     mov     ax, [res]
: : : : :     call    print_ax   
: : : : :     call    print_nl 
: : : : :     call    print_nl
: : : : :     lea     dx, sDone
: : : : :     call    prntStr   
: : : : :     popa
: : : : : 
: : : : : ;-------------------------
: : : : : ; Exit back to OS
: : : : : ;-------------------------
: : : : : exit:    
: : : : :     call    getch               ; wait for quit    
: : : : :     mov     ax, 4c00h           ; return with error code 0
: : : : :     int     21h                               
: : : : : 
: : : : : ends  
: : : : : 
: : : : :  loopTest db  0 
: : : : : 
: : : : : ;********************************
: : : : : ;
: : : : : ; Print integer as string (AX=integer)
: : : : : ;
: : : : : ;********************************  
: : : : : print_ax proc
: : : : : cmp ax, 0
: : : : : jne print_ax_r
: : : : :     push     ax
: : : : :     mov     al, '0'
: : : : :     mov     ah, 0eh
: : : : :     int     10h
: : : : :     pop      ax
: : : : :     ret 
: : : : : print_ax_r:
: : : : :     pusha
: : : : :     mov     dx, 0
: : : : :     cmp     ax, 0
: : : : :     je      pn_done
: : : : :     mov     bx, 10
: : : : :     div     bx    
: : : : :     call    print_ax_r
: : : : :     mov     ax, dx
: : : : :     add     al, 30h
: : : : :     mov     ah, 0eh
: : : : :     int     10h    
: : : : :     jmp     pn_done
: : : : : pn_done:
: : : : :     popa  
: : : : :     ret  
: : : : : print_ax endp
: : : : : 
: : : : :              
: : : : : ;*******************************************
: : : : : ;
: : : : : ; Prnt char (DL=char to print)
: : : : : ;
: : : : : ;*******************************************                  
: : : : : prntChar proc near
: : : : :     mov     ah, 02h
: : : : :     int     21h 
: : : : :     ret    
: : : : : prntChar endp                  
: : : : :   
: : : : :                   
: : : : : ;*******************************************
: : : : : ;
: : : : : ; Prnt $-terminating string (DS:DX=>string)
: : : : : ;
: : : : : ;*******************************************              
: : : : : prntStr proc near                          
: : : : :     mov     ah, 9
: : : : :     int     21h                              
: : : : :     ret         
: : : : : prntStr endp   
: : : : :     
: : : : : ;*******************************************
: : : : : ;
: : : : : ; Prnt newline/CR
: : : : : ;
: : : : : ;*******************************************
: : : : : print_nl proc 
: : : : :     push    ax  
: : : : :     push    dx  
: : : : :     mov     ah, 2
: : : : :     mov     dl, 0Dh
: : : : :     int     21h  
: : : : :     mov     dl, 0Ah
: : : : :     int     21h   
: : : : :     pop     dx 
: : : : :     pop     ax      
: : : : :     ret
: : : : : print_nl endp    
: : : : :     
: : : : :                     
: : : : : ;*******************************************
: : : : : ;
: : : : : ;  Get input into buffer (DS:DX=>buffer)
: : : : : ;  First byte in buffer = number of chars to read
: : : : : ;  ret\ number of chars read stored in second byte in buffer
: : : : : ;
: : : : : ;*******************************************
: : : : : scanStr proc    near 
: : : : :    mov     ah, 0ah
: : : : :    int     21h  
: : : : :    ret      
: : : : : scanStr endp
: : : : : 
: : : : : ;*******************************************
: : : : : ;
: : : : : ; Wait for any key press
: : : : : ;
: : : : : ;*******************************************
: : : : : getch proc near
: : : : :     mov     ah, 1
: : : : :     int     21h
: : : : :     ret                               
: : : : : getch endp                   
: : : : :              
: : : : :               
: : : : : end start ; set entry point and stop the assembler.
: : : : : 
: : : : : 
: : : : : 

: : : : : Hope this helps;
: : : : :
: : : : : ~mt2002

: : : : :
: : : : :
: : : : thanks a lot this is great but only problem is when i click emulate in emu8086 i get this message
: : : : "file NOT built, there are errors!"
: : : : (0) No ENDS for: code
: : : : (204) ends unmatched!
: : : : (30) No ENDS for: stack
: : : : (21) ends unmatched!
: : : : (18) No ENDS for: data
: : : : (16) ends unmatched!
: : : : (3) No ENDS for: code
: : : :
: : : : any ideas what these means and how i can sort them out? thanks a lot for all your help
: : : :
: : :
: : : ends is a directive meaning "end segment". Multiple segments are primarily used with *.exe programs.
: : :
: : : When creating a new project, in the "choose code template" dialog, Insure empty workspace is selected, and use flat assembler (fasm) synthax is not selected.
: : :
: : : Everything should assemble fine.
: : :

: : :
: : i have version 3.07 and theirs no option for empty workspace, when you click new you either have COM template, EXE template, BIN template, BOOT template. Also where is the option for "use flat assembler (fasm) synthax?
: :
:
: Select "Use EXE template". If Emu8086 generates code, delete the code and copy mine.
:
: *edit:
: ProgrammersHeaven only allows posts nested 10 times, so if you still need help, and are unable to post, feel free to either edit this post, or reply to an earilier post.
:

:
:
: i've got to make exe template, deleted all the code and copied yours in and now im gettins 100's of illegal instructions when it try's to complie

Report
Re: emu8086 help Posted by MT2002 on 21 Jan 2007 at 2:38 PM

i've got to make exe template, deleted all the code and copied yours in and now im gettins 100's of illegal instructions when it try's to complie


Referring to what? My code assembled fine in v. 4.04. Can you please post some of the errors?

Report
Re: emu8086 help Posted by super.rad on 21 Jan 2007 at 2:56 PM
sorry my mistake on that error, was copying the code from a reply and it had ":::" before every line which was causing those errors, but im still getting the no ENDS for: code and ends unmatched errors. Do you know where i can get a newer version from to see if its the version im using causing the errors
Report
Re: emu8086 help Posted by MT2002 on 21 Jan 2007 at 3:07 PM
sorry my mistake on that error, was copying the code from a reply and it had ":::" before every line which was causing those errors, but im still getting the no ENDS for: code and ends unmatched errors. Do you know where i can get a newer version from to see if its the version im using causing the errors


I got mine for the link you posted

http://www.emu8086.com/

Direct link to zip..

http://www.emu8086.com/files/emulator-demo.zip

Report
Re: emu8086 help Posted by super.rad on 21 Jan 2007 at 3:16 PM
This message was edited by super.rad at 2007-1-21 15:18:23

seems it didnt like the old version, downloaded the newer version and works fine, thanks a lot
EDIT: when it's running do i just type in the numbers, do they have to be seperated by comma's and what do i press when i have inputted all the numbers and want it to work out the highest number etc. thanks


Report
Re: emu8086 help Posted by MT2002 on 21 Jan 2007 at 3:26 PM
: This message was edited by super.rad at 2007-1-21 15:18:23

: seems it didnt like the old version, downloaded the newer version and works fine, thanks a lot
: EDIT: when it's running do i just type in the numbers, do they have to be seperated by comma's and what do i press when i have inputted all the numbers and want it to work out the highest number etc. thanks
:
:
:

Any character that is not a number (NaN) is ignored. So you can use any character to seperate numbers.. 30,25,09, 30 25 09, 30f25#09 all mean the same.

Also hit <enter> after inputting the numbers. When the program says to "Press any key to quit", any key should work.

Report
Re: emu8086 help Posted by super.rad on 26 Feb 2007 at 10:52 AM
Hi, could anyone have a look through this and add some comments to important pieces explaining what they do as i have no idea what any of this means. Thanks a lot.
PS if you need to know what the program does read the messages before this.

: [/blue]
       
: iNumInput equ 30                                                ; size of input buffers
:                                              
: data segment
:     sInNum db "Please input a series of numbers. ->$"     
:     sNum db "The largest number is: $"                 
:     sInputs db "Number of numbers to compare: $"
:     sCompare db "Comparing numbers...$"      
:     sDone db "Press any key to exit...$"
:     count dw 0                                                  ; storage for counting 
:     numInts dw 0                                                ; number of ints input      
:     integer dw 0                                                ; storage for integer        
:     prevInt dw 0                                                ; previous integer for comparing 
:     res     dw 0                                                ; result (largest interger)       
:     inputBuf db iNumInput, ?, iNumInput dup ('$'), '$'          ; input buffer     
:     numbrs dw iNumInput dub ('?')                               ; integer array   
: ends  
: 
: stack segment     
: 
:     dw   128  dup(0)
: ends
: 
: 
: ;******************************************
: ;
: ; Execution begins here
: ;
: ;******************************************
: 
: code segment
: start:
:     mov     ax, data            ; setup registers
:     mov     ds, ax
:     mov     es, ax            
:     lea     dx, sInNum          ; print string to get input
:     call    prntStr                   
:     call    print_nl       
:     lea     dx, inputBuf        ; get input
:     call    scanStr      
:     call    print_nl
:     lea     dx, sCompare
:     call    prntStr                                           
:                 
: ;--------------------------
: ; Convert chars to integers
: ;--------------------------
: ascii:     
:     pusha      
:     lea     bx, inputBuf+2      ; actual start of buffer   
:     xor     dx, dx
:     mov     cx, 0               ; counter offset (index counter)       
:       
: loop1:                          ;..This would be better with loopze instruction..
:     mov     dl, [bx]     
:     inc     bx                  ; move to next char           
:     cmp     dl, '$'             ; end of string?
:     je      loop1end        
:     cmp     dl, '0'             ; Insure character is valid
:     je      prnt
:     cmp     dl, '1'
:     je      prnt
:     cmp     dl, '2'
:     je      prnt
:     cmp     dl, '3'
:     je      prnt              
:     cmp     dl, '4'
:     je      prnt
:     cmp     dl, '5'
:     je      prnt
:     cmp     dl, '6'
:     je      prnt      
:     cmp     dl, '7'
:     je      prnt
:     cmp     dl, '8'
:     je      prnt
:     cmp     dl, '9'
:     je      prnt                        
:     ; not a valid number, so skip it
:     jmp loop1
: prnt:                         ; convert char to integer word
:     sub     dl, 48            ; ASCII chars begin at decimal=48
:     push    bx
:     inc     cx
:     lea     bx, numbrs
:     add     bx, cx 
:     mov     [bx], dl 
:     pop     bx
:     jmp     loop1                          
: loop1end:      
:     mov     [count], cx 
:     popa
: 
: ;-------------------------
: ; Perform actual computing
: ;-------------------------
: 
: compute:
:     pusha  
:     mov     dx, 0           ; current integer
:     mov     cx, [count]     ; count=number of words in array     
:     lea     bx, numbrs+1
:             
: loop2:                      ; ..would be better with loopze instruction..
:   
: ;------------------------
: ; .Convert chars into workable integer
: ;------------------------
:     dec     cx               ; no more chars?
:     cmp     cx, 0
:     je      loop2exit                               
:     mov     ax, [bx]         ; get first digit      
:     mov     dh, al           ; swap low order/high order words (integers stored in little-endian)
:     mov     dl, ah
:     mov     ax, dx            
:     mov     [integer], dx   ; store our integer 
:     mov     dl, 0             ; AH = tens place, AL=ones place (DX=AX)   
:     mov     dh, 10                          
:     mov     al, 0
:     mul     dx               ; multiply by dx (DX=10 for tens place)
:     mov     ax, dx           
:     mov     dx, [integer]   ; now second digit (ones place)
:     mov     dh, 0
:     add     ax, dx           ; Add ones place
:     mov     [integer], ax   ; integer = actual integeral value to compare
: 
: ;-----------------------
: ; .Test for largest number
: ;-----------------------
: 
:     mov     dl, [loopTest]   ; test for first time looping                 
:     cmp     dl, 0
:     je      loop3first
:     jmp     compare  
: loop3first:                  
:     mov     [prevInt], ax    ; first tme looping, so prevInt=curInt     
:     mov     [res], ax
:     mov     [loopTest], 1    ; set flag             
: compare:         
:     inc     [numInts]           ; ...one more integer         
:     mov     dx, [integer]    ; is current int larger then previous?
:     mov     ax, [prevInt]
:     cmp     dx, ax     
:     jge     greater   
:     jmp     less   
: greater:        
:     ; ax is bigger, but bigger then res?
:     mov     ax, dx
:     mov     ax, [res]
:     cmp     ax, dx
:     jge     largest  
:     mov     [res], dx       
:     mov     [integer], ax    
:     jmp     loop2end
: largest:
:     mov     [res], ax    ; yep--ax is largest       
:     jmp     loop2end
: less: 
:     mov     [integer], dx  ; nope--dx must be largest  
:  
: ;----------------------
: ; .Go to next char
: ;---------------------- 
: loop2end:        
:     mov     [prevInt], dx   ; store int to become next prev int                
:     inc     bx           ; jump to next number (got to inc on word bonderies)
:     inc     bx               
:     jmp     loop2                            
: loop2exit:    
:     popa
: 
: ;---------------------
: ; Print our answer
: ;---------------------
: prntRes:         
:     pusha   
:     call    print_nl  
:     lea     dx, sInputs
:     call    prntStr
:     call    print_nl 
:     mov     ax, [numInts]  ; numInts contains number of digits for each char..   
:     inc     ax       
:     mov     bl, 02h        ;...because each int is 2 digits, we divide it (ignore overflow)
:     div     bl
:     call    print_ax  
:     call    print_nl
:     lea     dx, sNum
:     call    prntStr   
:     mov     ax, [res]
:     call    print_ax   
:     call    print_nl 
:     call    print_nl
:     lea     dx, sDone
:     call    prntStr   
:     popa
: 
: ;-------------------------
: ; Exit back to OS
: ;-------------------------
: exit:    
:     call    getch               ; wait for quit    
:     mov     ax, 4c00h           ; return with error code 0
:     int     21h                               
: 
: ends  
: 
:  loopTest db  0 
: 
: ;********************************
: ;
: ; Print integer as string (AX=integer)
: ;
: ;********************************  
: print_ax proc
: cmp ax, 0
: jne print_ax_r
:     push     ax
:     mov     al, '0'
:     mov     ah, 0eh
:     int     10h
:     pop      ax
:     ret 
: print_ax_r:
:     pusha
:     mov     dx, 0
:     cmp     ax, 0
:     je      pn_done
:     mov     bx, 10
:     div     bx    
:     call    print_ax_r
:     mov     ax, dx
:     add     al, 30h
:     mov     ah, 0eh
:     int     10h    
:     jmp     pn_done
: pn_done:
:     popa  
:     ret  
: print_ax endp
: 
:              
: ;*******************************************
: ;
: ; Prnt char (DL=char to print)
: ;
: ;*******************************************                  
: prntChar proc near
:     mov     ah, 02h
:     int     21h 
:     ret    
: prntChar endp                  
:   
:                   
: ;*******************************************
: ;
: ; Prnt $-terminating string (DS:DX=>string)
: ;
: ;*******************************************              
: prntStr proc near                          
:     mov     ah, 9
:     int     21h                              
:     ret         
: prntStr endp   
:     
: ;*******************************************
: ;
: ; Prnt newline/CR
: ;
: ;*******************************************
: print_nl proc 
:     push    ax  
:     push    dx  
:     mov     ah, 2
:     mov     dl, 0Dh
:     int     21h  
:     mov     dl, 0Ah
:     int     21h   
:     pop     dx 
:     pop     ax      
:     ret
: print_nl endp    
:     
:                     
: ;*******************************************
: ;
: ;  Get input into buffer (DS:DX=>buffer)
: ;  First byte in buffer = number of chars to read
: ;  ret\ number of chars read stored in second byte in buffer
: ;
: ;*******************************************
: scanStr proc    near 
:    mov     ah, 0ah
:    int     21h  
:    ret      
: scanStr endp
: 
: ;*******************************************
: ;
: ; Wait for any key press
: ;
: ;*******************************************
: getch proc near
:     mov     ah, 1
:     int     21h
:     ret                               
: getch endp                   
:              
:               
: end start ; set entry point and stop the assembler.
: 
: 
: 




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.