SpareNet Servers Advertising & Link Exchange

اطلاعیه

بستن
هیچ اطلاعیه ای هنوز ایجاد نشده است .

تاپیک جامع سورس کد های Assembly

بستن
X
 
  • فیلتر
  • زمان
  • نمایش
پاک کردن همه
نوشته‌های جدید

  • تاپیک جامع سورس کد های Assembly

    سلام بر عزیزان در این تاپیک سورس کد ها و نمونه کد های زبان ماشین یا Assembly قرار میگیرد .

    برنامه چاپ و محاسبه سری فیبوناچی :

    کد:
    ;****************************************************************************
    PrintString:
        mov    bx, 1        ; write to stdout
        mov     ah, 040h        ; write to file handle
        int    21h        ; ignore return value
        ret            ;
    
    ;****************************************************************************
    ;
    ; AddNumbers
    ; add number 2 at ds:si to number 1 at es:di of width cx
    ;
    ;
    ; INPUT:     es:di ==> number1, ds:si ==> number2, cx= max width
    ; OUTPUT:    CF set on overflow
    ; DESTROYED: ax, si, di
    ;
    ;****************************************************************************
    AddNumbers:
        std            ; go from LSB to MSB
        clc            ;
        pushf            ; save carry flag
    .top
        mov    ax,0f0fh    ; convert from ASCII BCD to BCD
        and      al,[si]        ; get next digit of number2 in al
        and    ah,[di]        ; get next digit of number1 in ah
        popf            ; recall carry flag
        adc    al,ah        ; add these digits
        aaa            ; convert to BCD
        pushf            ;
        add    al,'0'        ; convert back to ASCII BCD digit
        stosb            ; save it and increment both counters
        dec    si        ;
        loop    .top        ; keep going until we've got them all
        popf            ; recall carry flag
        ret            ;
    
    ;****************************************************************************
    ;
    ; IncrementCount
    ; increments a multidigit term counter by one
    ;
    ; INPUT:     none
    ; OUTPUT:    CF set on overflow
    ; DESTROYED: ax, cx, di
    ;
    ;****************************************************************************
    IncrementCount:
        mov    cx,cntDigits    ;
        mov    di,counter+cntDigits-1
        std            ; go from LSB to MSB
        stc            ; this is our increment
        pushf            ; save carry flag
    .top
        mov    ax,000fh    ; convert from ASCII BCD to BCD
        and    al,[di]        ; get next digit of counter in al
        popf            ; recall carry flag
        adc    al,ah        ; add these digits
        aaa            ; convert to BCD
        pushf            ;
        add    al,'0'        ; convert back to ASCII BCD digit
        stosb            ; save and increment counter
        loop    .top        ;
        popf            ; recall carry flag
        ret            ;
        
    ;****************************************************************************
    ;
    ; CRLF
    ; prints carriage return, line feed pair to stdout
    ;
    ; INPUT:     none
    ; OUTPUT:    CF set on error, AX = error code if carry set
    ; DESTROYED: ax, bx, cx, dx
    ;
    ;****************************************************************************
    CRLF:    mov    dx,eol        ;
        mov    cx,eollen    ;
        jmp    PrintString    ;
    
    ;****************************************************************************
    ; static data
    ;****************************************************************************
    eol    db  13,10        ; DOS-style end of line
    eollen    equ $ - eol
    
    msg1    db  'Fibonacci('    ;
    msg1len    equ $ - msg1
    
    msg2    db  '): '        ;
    msg2len    equ $ - msg2
    ;****************************************************************************
    ; initialized data
    ;****************************************************************************
    term dd maxTerms        ;
    ;****************************************************************************
    ; unallocated data
    ;
    ; A better way to do this would be to actually ask for a memory
    ; allocation and use that memory space, but this is a DOS COM file
    ; and so we are given the entire 64K of space.   Technically, this
    ; could fail since we *might* be running on a machine which doesn't
    ; have 64K free.  If you're running on such a memory poor machine,
    ; my advice would be to not run this program.
    ;
    ;****************************************************************************
    ; static data
    counter:            ;
    num1 equ counter+cntDigits    ;
    num2 equ num1+digits        ;
            
    سورس کد برنامه آلارم به زبان اسمبلی :

    کد:
    Alarm
    
    cseg    segment para public 'code'
    org    100h
    alarm    proc far
    
    ; Memory-resident program to intercept the timer interrupt and display the
    ; system time in the upper right-hand corner of the display.
    ; This program is run as 'ALARM hh:mm x', where hh:mm is the alarm time and
    ; x is '-' to turn the display off. Any other value of x or no value will
    ; turn the clock on
    
    intaddr equ 1ch*4        ; interrupt address
    segaddr equ 62h*4        ; segment address of first copy
    mfactor equ 17478        ; minute conversion factor * 16
    whozat    equ 1234h        ; signature
    color    equ 14h         ; color attribute
    
        assume cs:cseg,ds:cseg,ss:nothing,es:nothing
        jmp p150        ; start-up code
    
    jumpval dd 0            ; address of prior interrupt
    signature dw whozat        ; program signature
    state    db 0            ; '-' = off, all else = on
    wait    dw 18            ; wait time - 1 second or 18 ticks
    hour    dw 0            ; hour of the day
    atime    dw 0ffffh        ; minutes past midnite for alarm
    acount    dw 0            ; alarm beep counter - number of seconds (5)
    atone    db 5            ; alarm tone - may be from 1 to 255 - the
                    ; higher the number, the lower the frequency
    aleng    dw 8080h        ; alarm length (loop count) may be from 1-FFFF
    
    dhours    dw 0            ; display hours
        db ':'
    dmins    dw 0            ; display minutes
        db ':'
    dsecs    dw 0            ; display seconds
        db '-'
    ampm    db 0            ; 'A' or 'P' for am or pm
        db 'm'
    
    tstack    db 16 dup('stack   ')   ; temporary stack
    estack    db 0            ; end of stack
    holdsp    dw 0            ; original sp
    holdss    dw 0            ; original ss
    
    p000:                ; interrupt code
        push ax         ; save registers
        push ds
        pushf
    
        push cs
        pop ds            ; make ds=cs
        mov ax,wait        ; check wait time
        dec ax            ; zero?
        jz p010         ; yes - 1 second has elapsed
        mov wait,ax        ; not this time
        jmp p080        ; return
    
    p010:    cli            ; disable interrupts
        mov ax,ss        ; save stack
        mov holdss,ax
        mov holdsp,sp
        mov ax,ds
        mov ss,ax        ; point to internal stack
        mov sp,offset estack
        sti            ; allow interrupts
    
        push bx         ; save other registers
        push cx
        push dx
        push es
        push si
        push di
        push bp
    
        mov ax,18        ; reset wait time
        mov wait,ax
    
        mov al,state        ; are we disabled?
        cmp al,'-'
        jnz p015        ; no
        jmp p070
    
    p015:    mov ah,0        ; read time
        int 1ah         ; get time of day
        mov ax,dx        ; low part
        mov dx,cx        ; high part
        mov cl,4
        shl dx,cl        ; multiply by 16
        mov bx,ax
        mov cl,12
        shr bx,cl        ; isolate top 4 bits of ax
        add dx,bx        ; now in upper
        mov cl,4
        shl ax,cl        ; multiply by 16
        mov bx,mfactor        ; compute minutes
        div bx            ; minutes in ax, remainder in dx
        cmp ax,atime        ; time to sound the alarm?
        jnz p020        ; no
        call p100        ; yes - beep the speaker twice
        push ax
        mov ax,acount        ; get beep count
        dec ax            ; down by 1
        mov acount,ax        ; save beep count
        cmp ax,0        ; is it zero?
        jnz p018        ; no - keep alarm on
        mov ax,0ffffh        ; turn off alarm
        mov atime,ax
    p018:    pop ax
    
    p020:    mov dsecs,dx        ; save remainder
        mov bx,60        ; compute hours
        xor dx,dx        ; zero it
        div bx            ; hours in ax, minutes in dx
        mov dmins,dx        ; save minutes
    
        cmp ax,0        ; midnight?
        jnz p030        ; no
        mov ax,12        ; yes
        jmp p040a        ; set am
    
    p030:    cmp ax,12        ; before noon?
        jb p040a        ; yes - set am
        jz p040p        ; noon - set pm
        sub ax,12        ; convert the rest
    p040p:    mov bl,'p'
        jmp p040x
    
    p040a:    mov bl,'a'
    
    p040x:    mov ampm,bl
        aam            ; fix up hour
        cmp ax,hour        ; top of the hour?
        jz p060         ; no
    
        mov hour,ax
        call p120        ; beep the speaker once
    
    p060:    add ax,3030h        ; convert hours to ascii
        xchg ah,al
        mov dhours,ax
    
        mov ax,dmins        ; get minutes
        aam
        add ax,3030h        ; convert to ascii
        xchg ah,al
        mov dmins,ax
    
        mov ax,dsecs        ; get seconds (remainder)
        xor dx,dx
        mov bx,60
        mul bx
        mov bx,mfactor
        div bx            ; seconds in ax
        aam
        add ax,3030h
        xchg ah,al
        mov dsecs,ax
    
        xor ax,ax        ; check monitor type
        mov es,ax
        mov ax,es:[410h]    ; get config byte
        and al,30h        ; isolate monitor type
        cmp al,30h        ; color?
        mov ax,0b000h        ; assume mono
        jz p061         ; its mono
    
        mov ax,0b800h        ; color screen address
    
    p061:    mov dx,es:[463h]    ; point to 6845 base port
        add dx,6        ; point to status port
    
        mov es,ax        ; point to monitor
        mov bh,color        ; color in bh
        mov si,offset dhours    ; point to time
        mov di,138        ; row 1, col 69
        cld
        mov cx,11        ; loop count
    
    p062:    mov bl,[si]        ; get next character
    
    p063:    in al,dx        ; get crt status
        test al,1        ; is it low?
        jnz p063        ; no - wait
        cli            ; no interrupts
    
    p064:    in al,dx        ; get crt status
        test al,1        ; is it high?
        jz p064         ; no - wait
    
        mov ax,bx        ; move color & character
        stosw            ; move color & character again
        sti            ; interrupts back on
        inc si            ; point to next character
        loop p062        ; done?
    
    p070:    pop bp            ; restore registers
        pop di
        pop si
        pop es
        pop dx
        pop cx
        pop bx
        cli            ; no interrupts
        mov ax,holdss
        mov ss,ax
        mov sp,holdsp
        sti            ; allow interrupts
    
    p080:    popf
        pop ds
        pop ax
        jmp cs:[jumpval]
    
    p100    proc near        ; beep the speaker twice
        call p120
        push cx
        mov cx,20000
    p105:    loop p105        ; wait around
        pop cx
        call p120
        push cx
        mov cx,20000
    p106:    loop p106        ; wait around
        pop cx
        call p120
        ret
    p100    endp
    
    p120    proc near        ; beep the speaker once
        push ax
        push cx
        mov al,182
        out 43h,al        ; setup for sound
        mov al,0
        out 42h,al        ; low part
        mov al,atone        ; get alarm tone
        out 42h,al        ; high part
        in al,61h
        push ax         ; save port value
        or al,3
        out 61h,al        ; turn speaker on
        mov cx,aleng        ; get loop count
    p125:    loop p125        ; wait around
        pop ax            ; restore original port value
        out 61h,al        ; turn speaker off
        pop cx
        pop ax
        ret
    p120    endp
    
    p150:                ; start of transient code
        mov dx,offset copyr
        call p220        ; print copyright
        mov ax,0
        mov es,ax        ; segment 0
        mov di,segaddr+2    ; this program's prior location
        mov ax,es:[di]        ; get prior code segment
        mov es,ax        ; point to prior program segment
        mov di,offset signature
        mov cx,es:[di]        ; is it this program?
        cmp cx,whozat
        jnz p160        ; no - install it
        call p200        ; set state & alarm
        int 20h         ; terminate
    
    p160:    mov di,segaddr+2    ; point to int 62h
        mov ax,0
        mov es,ax        ; segment 0
        mov ax,ds        ; get current ds
        mov es:[di],ax        ; set int 62h
        mov si,offset jumpval
        mov di,intaddr        ; point to timer interrupt
        mov bx,es:[di]        ; get timer ip
        mov ax,es:[di+2]    ; and cs
        mov [si],bx        ; save prior ip
        mov [si+2],ax        ; and cs
        mov bx,offset p000
        mov ax,ds
        cli            ; clear interrupts
        mov es:[di],bx        ; set new timer interrupt
        mov es:[di+2],ax
        sti            ; set interrupts
        push ds
        pop es
        call p200        ; set state & alarm
        mov dx,offset p150    ; last byte of resident portion
        inc dx
        int 27h         ; terminate
    
    p200    proc near        ; set state & alarm
        mov si,80h        ; point to command line
        mov ax,0
        mov di,0ffffh        ; init hours
        mov bh,0
        mov ch,0
        mov dh,0        ; : counter
        mov es:[state],bh    ; turn clock on
        mov cl,[si]        ; get length
        jcxz p210        ; it's zero
    
    p203:    inc si            ; point to next char
        mov bl,[si]        ; get it
        cmp bl,'-'              ; is it a minus?
        jnz p204        ; no
        mov es:[state],bl    ; turn clock off
        push dx
        mov dx,offset msg3    ; print msg
        call p220
        pop dx
        jmp p206
    
    p204:    cmp dh,2        ; seen 2nd colon?
        jz p206         ; yes - ignore seconds
        cmp bl,':'              ; colon?
        jnz p205        ; no
        inc dh
        cmp dh,2        ; second colon?
        jz p206         ; yes - ignore seconds
        push cx
        push dx
        mov cx,60
        mul cx            ; multiply current ax by 60
        pop dx
        pop cx
        mov di,ax        ; save hours
        mov ax,0
        jmp p206
    p205:    cmp bl,'0'
        jb p206         ; too low
        cmp bl,'9'
        ja p206         ; too high - can be a problem
        sub bl,'0'              ; convert it to binary
        push cx
        push dx
        mov cx,10
        mul cx            ; multiply current value by 10
        add ax,bx        ; and add latest digit
        pop dx
        pop cx
    p206:    loop p203        ; done yet?
        cmp di,0ffffh        ; any time to set?
        jz p210         ; no
        add ax,di        ; add hours
        cmp ax,24*60
        jb p209         ; ok
        mov dx,offset msg1    ; print error message
        call p220
        jmp p210
    
    p209:    mov es:[atime],ax    ; save minutes past midnight
        mov ax,5
        mov es:[acount],ax    ; set alarm count
        mov dx,offset msg2    ; print set msg
        call p220
    p210:    ret
    p200    endp
    
    p220    proc near        ; print message
        push ax
        mov ah,9
        int 21h
        pop ax
        ret
    p220    endp
    
    copyr    db 'Alarm - Clock',10,13,'$'
    msg1    db 'Invalid time - must be from 00:00 to 23:59',10,13,'$'
    msg2    db 'Resetting alarm time',10,13,'$'
    msg3    db 'Turning clock display off',10,13,'$'
    
    alarm    endp
    cseg    ends
    end    alarm
    [align=center][/align]

  • #2
    RE: تاپیک جامع سورس کد های Assembly

    سورس کد برنامه ساعت به زبان اسمبلی :

    کد:
    Clock
    
    CGROUP     GROUP VECTOR,CODESEG
    VECTOR     SEGMENT AT 0H
         DB    6CH DUP(?)        ;FILLER
    TIME_LO  DW    ?            ;DOS TIME
    TIME_HI  DW    ?            ;DOS TIME
    VEC_IP     DW                ;CLOCK UPDATE VECTOR IP
    VEC_CS     DW                ;CLOCK UPDATE VECTOR CS
    VECTOR     ENDS
    
    CODESEG  SEGMENT PARA
         ASSUME CS:CODESEG,DS:CGROUP
         ORG   100H
    CLK     PROC  FAR
         JMP   SETUP            ;ATTACH TO DOS
    INTRPT     LABEL DWORD
    INT_IP     DW    0            ;OLD UPDATE VECTOR IP
    INT_CS     DW    0            ;OLD UPDATE VECROR CS
    TICKS     DW    0            ;TICK COUNTER
    SCR_OFF  DB    0,0            ;SCREEN OFFSET IN BUFFER
    CRT_PORT DW    0            ;SCREEN STATUS PORT
    flag     db    0
    TIME     DB    8 DUP(':',0BH)       ;TIME SAVE AREA
    CLK_INT  LABEL NEAR
         PUSH  AX            ;SAVE REGISTERS
         PUSH  CX
         PUSH  DI
         PUSH  SI
         PUSH  DS
         PUSH  ES
         PUSHF                ; AND FLAGS
         CALL  CS:[INTRPT]        ;DO OLD UPDATE INTERRUPT
         MOV   CX,0040H         ;GET SEGMENT OF DOS TABLE
         MOV   DS,CX            ;PUT IN DS
         MOV   CX,CS:TICKS        ;GET TICK COUNT
         INC   CX            ;INCREMENT IT
         CMP   CX,20        ;01F4H           ;HAS A MINUTE GONE BY?
         JB    NO_MINUTE        ;NO, MOVE ON
         CALL  UPDATE            ;YES, UPDATE CLOCK AND
         MOV   CX,0            ; RESET TICK COUNTER
    NO_MINUTE:
         MOV   CS:TICKS,CX        ;SAVE UPDATED TICK COUNT
         MOV   CX,0B000H        ;GET VIDEO SEGMENT
         MOV   ES,CX            ;PUT IN ES
         MOV   DX,CS:CRT_PORT        ;GET CRT STATUS PORT ADDR
         MOV   DI,WORD PTR CS:SCR_OFF  ;GET SCREEN BUFFER OFFSET
         LEA   SI,CS:TIME        ;GET DOS TIME
         MOV   CX,16            ;SET UP TO MOVE 10 BYTES
         CLI                ;DISABLE OTHER INTERRUPTS
    WAIT1:     IN    AL,DX            ;READ CRT STATUS
         TEST  AL,1            ;CHECK FOR VERTICAL RETRACE
         JNZ   WAIT1            ;WAIT FOR RETRACE LOW
         MOV   AH,CS:[SI]        ;GET FIRST BYTE TO MOVE
    WAIT2:     IN    AL,DX            ;GET CRT STATUS
         TEST  AL,1            ;CHECK FOR VERTICAL RETRACE
         JZ    WAIT2            ;WAIT FOR RETRACE HIGH
         MOV   ES:[DI],AH        ;MOVE BYTE TO SCREEN
         INC   DI            ;INCREMENT INDEX
         INC   SI
         LOOP  WAIT1            ;MOVE NEXT BYTE
         STI                ;ENABLE INTERRUPTS
         POP   ES            ;RESTORE REGISTERS
         POP   DS
         POP   SI
         POP   DI
         POP   CX
         POP   AX
         IRET                ;RETURN FROM INTERRUPT
    CLK     ENDP
    UPDATE     PROC  NEAR
         PUSH  AX            ;SAVE REGISTERS
         PUSH  BX
         PUSH  CX
         PUSH  DX
         PUSH  DS
         MOV   AX,0040H         ;GET ADDRESS OF DOS TABLE
         MOV   DS,AX            ;PUT IN DS
         MOV   AX,TIME_HI        ;GET HIGH BYTE OF DOS TIME
         mov   flag,0            ;am flag
    HOUR:     CMP   AX,0CH            ;CONVERT TO HOURS
         JLE   H1
         mov   flag,1            ;set to pm
         SUB   AX,0CH
         JMP   HOUR
    H1:     AAM                ;CONVERT TO ASCII
         ADD   AX,3030H
         LEA   BX,CS:TIME        ;GET ADDRESS OF TIME AREA
         MOV   CS:[BX],AH        ;SAVE HOURS FIRST DIGIT
         MOV   CS:[BX+2],AL        ;SAVE HOURS SECOND DIGIT
         MOV   AX,TIME_LO        ;GET DOS TIME LOW BYTE
         MOV   CX,8H            ;CONVERT TO MINUTES
         SHR   AX,CL
         MOV   DX,3CH
         MUL   DL
         SHR   AX,CL
         AAM                ;CONVERT TO ASCII
         ADD   AX,3030H
         MOV   CS:[BX+6],AH        ;SAVE MINUTES FIRST DIGIT
         MOV   CS:[BX+8],AL        ;SAVE MINUTES SECOND DIGIT
         mov   byte ptr cs:[bx+12],'a'
         cmp   flag,0            ;is it am?
         jz    goahead
         mov   byte ptr cs:[bx+12],'p'
    goahead:
         mov   byte ptr cs:[bx+14],'m'
         POP   DS            ;RESTORE REGISTERS
         POP   DX
         POP   CX
         POP   BX
         POP   AX
         RET
    UPDATE     ENDP
    SETUP:     MOV   AX,0            ;GET ADDRESS OF VECTOR TABLE
         MOV   DS,AX            ;PUT IN DS
         CLI                ;DISABLE FURTHER INTERRUPTS
         MOV   AX,[VEC_IP]        ;GET ADDRESS OF OLD UPDATE IP
         MOV   CS:[INT_IP],AX        ;SAVE IT
         MOV   AX,[VEC_CS]        ;GET ADDRESS OF OLD UPDATE CS
         MOV   CS:[INT_CS],AX        ;SAVE IT
         MOV   VEC_IP,OFFSET CLK_INT ;PUT ADDRESS OF CLK IN VECTOR IP
         MOV   VEC_CS,CS        ;PUT CS OF CLK IN VECTOR CS
         STI                ;ENABLE INTERRUPTS
         MOV   AH,0FH            ;READ VIDEO STATUS
         INT   10H
         SUB   AH,8            ;SUBTRACT 8 CHAR TIME FROM NCOLS
         SHL   AH,1            ;MULTIPLY BY 2 FOR ATTRIBUTE
         MOV   CS:SCR_OFF,AH        ;SAVE SCREEN TIME LOCATION
         MOV   WORD PTR CS:CRT_PORT,03BAH  ;SAVE MONO STATUS PORT ADDR
         TEST  AL,4            ;CHECK FOR COLOR MONITOR
         JNZ   MONO            ;IF MONO, MOVE ON
         ADD   WORD PTR CS:SCR_OFF,8000H   ;ADD COLOR OFFSET TO TIME OFFSET
         MOV   WORD PTR CS:CRT_PORT,03DAH  ;SAVE COLOR STATUS PORT ADDR
    MONO:     CALL  UPDATE            ;DO FIRST UPDATE & PRINT TIME
         MOV   DX,OFFSET SETUP        ;GET END ADDRESS OF NEW INTERRUPT
         INT   27H            ;TERMINATE AND REMAIN RESIDENT
         DB    117 DUP(0)        ;FILLER
    CODESEG  ENDS
         END   CLK
    برنامه نمایش اطلاعات حافظه :

    کد:
    
    kbd             equ     16h             ;keyboard irq
    msdos           equ     21h             ;MSDOS irq
    
    reset           equ     0dh             ;disk reset
    dfopen          equ     0fh             ;open disk file
    dfclose         equ     10h             ;close disk file
    searchf         equ     11h             ;search first
    searchn         equ     12h             ;search next
    seqread         equ     14h             ;sequential disk read
    seqwrite        equ     15h             ;     "       "  write
    setdta          equ     1ah             ;set disk transfer area address
    createf         equ     3ch             ;create file with handle
    openf           equ     3dh             ;open file with handle
    closef          equ     3eh             ;close file with handle
    readf           equ     3fh             ;read from file with handle
    writef          equ     40h             ;write to file with handle
    setfp           equ     42h             ;set file pointer
    allocmem        equ     48h             ;allocate memory
    freemem         equ     49h             ;free memory
    changebs        equ     4ah             ;change block size
    findfirst       equ     4eh             ;find first file
    exit            equ     4c00h           ;msdos exit
    
    [BITS 16]                               ;NASM stuff
    [ORG 0x100]
    
    s1:
            mov     ax,cs                   ;get code segment
            mov     ds,ax                   ;use it now
            mov     [comseg],ds             ;save it there        
    
            mov     si,0080h                ;DOS command line page 0
            lodsb                           ;load size of command line
            cmp     al,0                    ;anything on command line ?
            jbe     usage                   ;noo, show usage
            cbw                             ;extend AL to AX
            xchg    bx,ax                   ;swap size to bx for indexing
            mov     byte [bx+si],0          ;null terminate command line
            call    parse                   ;parse command line
            jmp     main                    ;go on with main
    usage:  mov     bx,utext                ;pointer usage text
            jmp     errout                  ;skip this
    main:
            mov     si,inbuff               ;check for valid HEX input
            mov     bx,errt1                ;proper text
    ishex:  lodsb                           ;get the char
            cmp     al,'0'
            jb      errout
            and     al,0dfh                 ;force UPPERCASE
            cmp     al,'F'                  ;>F ?
            ja      errout                  ;yeahh, dump this
            loop    ishex
            call    hexbin                  ;make hex bin
                                            ;start address now in EDX
            mov     ax,dx                   ;get low word (segment)
            mov     es,ax                   ;start segment
            shr     edx,16                  ;shift in offset
            mov     di,dx                   ;start offset
    dopage:
            push    es                      ;save registers
            push    di
            push    ds
            push    si
            mov     ax,es
            mov     ds,ax                   ;make ds=es
            mov     si,di                   ;and si=di
            
            call    showpage                ;show it
            
            pop     si                      ;restore registers
            pop     ds
            pop     di
            pop     es
            add     di,512                  ;adjust memory position
    
            ;xor     ah,ah                  ;wait for ANY key
            ;int     kbd
            
            mov     bx,text                 ;show message
            call    write
            mov     ah,0                    ;wanna see next screen  ?
            int     kbd                     ;chek out keyboard buffer
            and     al,0DFh                 ;force UPPER CASE
            cmp     al,"Q"                  ;wanna quit ?
            je      quit                    ;yeahh
            jmp     dopage
    errout:
            call    write
    quit:   
            mov     ax,exit
            int     msdos
    
    ;***********************************************************
    ;*      Convert ascii hex to 32 bit binary
    ;*      Input = command line buffer, output EDX
    ;***********************************************************
    hexbin:
            mov     si,inbuff               ;pointer command line buffer
            xor     edx,edx                 ;clear binary output
    aschexbin:
            lodsb
            cmp     al,'0'                  ;< 0
            jb      notasc                  ;yes invalid character
            cmp     al,'9'                  ;<= 9
            jbe     astrip                  ;yes, strip high 4 bits
            and     al,05fh                 ;force upper case
            cmp     al,'A'                  ;< ascii A
            jb      notasc                  ;yes, invalid character
            cmp     al,'F'                  ;> ascii F
            ja      notasc                  ;yes, invalid character
            add     al,9                    ;ok, add 9 for strip
    astrip:
            and     al,0fh                  ;strip high 4 bits
            mov     cx,4                    ;set shift count
            shl     edx,cl                  ;rotate EDX 4 bits
            xor     ah,ah                   ;zero out AH
            cbw
            add     edx,eax                 ;add digit to value
            jmp     aschexbin               ;continue
    notasc: ret
    
    ;*********************************************************************
    ;*      Format and show the stuff in a "sector"
    ;*      Input SI
    ;*********************************************************************
    showpage:
            mov     cx,32                   ;32*16=512
    arow:   push    cx
            mov     di,outline              ;output buffer
            mov     cx,16                   ;process 16 bytes
    hexrow: push    cx
            lodsb                           ;load al with byte
            mov     dl,al                   ;get value
            mov     cx,2                    ;2 nibbles
    chexb:  push    cx                      ;save that
            mov     cl,4                    ;4 bits
            rol     dl,cl                   ;rotate source left
            mov     al,dl                   ;move digit into AL
            and     al,15                   ;clear high nibble
            daa                             ;adjust AL if A through F
            add     al,240                  ;bump the carry
            adc     al,40h                  ;convert HEX to ASCII
            stosb                           ;copy to buffer
            pop     cx                      ;get digit counter
            loop    chexb                   ;next digit
            mov     al,32                   ;copy a SPACE
            stosb
            pop     cx                      ;restore loop counter
            loop    hexrow                  ;loop on
            mov     al,32                   ;copy 2 spaces
            stosb
            stosb
            sub     si,16                   ;adjust source back
            mov     cx,16                   ;copy ASCII bytes
    cccp:   lodsb
            cmp     al,32                   ;< SPACE ?
            jb      noa                     ;yeahh, skip it
            stosb                           ;no, store in buffer
            jmp     next
    noa:    mov     al,'.'
            stosb
    next    loop    cccp   
            mov     al,13
            stosb
            mov     al,10
            stosb
            mov     al,0                    ;null terminate line
            stosb
            mov     bx,outline              ;show the line
            call    write
            pop     cx
            cmp     cx,17
            jne     nopause
            push    ds
            mov     ax,cs
            mov     ds,ax
            mov     bx,text1
            call    write
            pop     ds
            xor     ah,ah
            int     kbd
    nopause:
            loop    arow                    ;next 16 bytes
            ret
    
    ;************************************************************************'
    ;*      Convert bin WORD to HEX ascii. Input DX. Result in Numbuff      *
    ;************************************************************************
    binhex: pusha       
            mov     di,numbuff              ;destination buffer
            mov     dx,[count]              ;binary number
            mov     cx,4                    ;four nibbles
    convhex:
            push    cx                      ;save counter
            mov     cl, 4                   ;4 bits
            rol     dx, cl                  ;rotate source left
            mov     al, dl                  ;move digit into AL
            and     al, 15                  ;clear high nibble
            daa                             ;adjust AL if A through F
            add     al, 240                 ;bump the carry
            adc     al, 40h                 ;convert HEX to ASCII
            stosb                           ;copy to buffer
            pop     cx                      ;get digit counter
            loop    convhex                 ;next digit
            mov     al,32                   ;copy a space
            stosb
            mov     al,0                    ;null terminate
            stosb
            popa
            ret
    
    ;*************************************************************************
    ;*       Writes out the NULL terminated text supplied in BX.             *
    ;*       OR writes out data,BX and size,CX if called at lwrite.          *
    ;*************************************************************************
    write:  pusha
            mov     si,bx                   ;copy to SI
            mov     cx,0                    ;clear count
    wloop:  lodsb                           ;load AL with SI
            cmp     al,0                    ;end of line ?
            je      lwrite                   ;yeahh
            inc     cx                      ;no, incrase byte count
            jmp     wloop                   ;test next byte
    lwrite: mov     dx,bx                   ;text address in DX
            mov     bx,1                    ;filehandle standard output = 1
            mov     ah,writef               ;MS-DOS writefile with handle is 040
            int     msdos                   ;write buffer to standard output
            popa
            ret                             ;done
    
    ;*************************************************************************
    ;*      My kind of command line parsing. It just checks if there?s
    ;*      any blankspaces between the options. The parameters ends up
    ;*      in the inbuff separated by 0:s, binary zeroes.
    ;*************************************************************************
    parse:
            mov     di,inbuff               ;our buffer
    ifspc:  cmp     byte [si],32            ;leading space  ?
            jne     nospc                   ;noo
            inc     si                      ;yeahh, dump that
            jmp     ifspc                   ;check next
    nospc:  mov     cx,1                    ;were here, so we got one arg
    copy1:  lodsb                           ;load byte SI to AL
            cmp     al,0                    ;0 ?(end of line)
            je      done                    ;yeahh
            cmp     al,32                   ;SPACE ?
            je      cop2                    ;yeah
            stosb                           ;noo, move AL to DI, incrase DI
            jmp     copy1                   ;go on
    cop2:   mov     byte [di],0             ;null terminate
            add     cx,1
            inc     di                      ;dump that byte(SPACE)
            jmp     copy1                   ;back
    done:   mov     byte [di],0             ;null terminate
            ret                             ;return
    
    
    ;*************************** DATA STUFF **********************************
    
    XMS_SEGMENT     dw 0
    XMS_OFFSET      dw 0
    
    inbuff          times 64 dw 0           ;128 byte command line buffer
    outline         times 40 dw 0           ;buffer output line
    numbuff         times 7 dw 0            ;word ascii number buffer
    comseg          dw 0
    count           dw 0
    bcount          dw 0
    acount          dw 0
    
    ;outbuff         times 512 db 0
    
    
    utext           db      'WWW',13,10
                    db      'Usage: Showmem [start address].',13,10
                    db      'Start address = Hexadecimal.',13,10,0
    text:           db      13,10,'Q = Quit. Any key = Next page.',13,10,0
    text1:          db      13,10,'Any Key = Next 256 Bytes.',13,10,0
    errt1:          db      'That address is not hexadecimal.',13,10,0
    
    s2:
    
    END
    [align=center][/align]

    نظر


    • #3
      RE: تاپیک جامع سورس کد های Assembly

      سورس کد برنامه stepper motor به زبان اسمبلی :

      تست و کامپایل با تولز emu8086

      کد:
       #start=stepper_motor.exe#
          #start=led_display.exe#
      
      
      
      data segment
      ANGLE  dw 0, 1125, 2250, 3375, 4500, 5625, 6750, 7875, 9000, 10125,
         dw 11250, 12375, 13500, 14625, 15750, 16875, 18000, 019125,
         dw 020250, 021375, 022500, 023625, 024750, 025875, 027000, 028125,
         dw 029250, 030375, 031500, 032625, 033750, 034875, 036000
      
      ; words for the menu
      menu db "MENU", 13, 10
       db " ", 13, 10
       db "                1- Reset", 13, 10
       db "                2- Select clockwise or counterclockwise", 13, 10
       db "                3- Select continuous or keyboard input", 13, 10
       db "                4- Turn", 13, 10     
       db "                >- Turn Right", 13, 10
       db "                <- Turn Left", 13, 10
       db " ", 13, 10
       db "                Q-QUIT", 13, 10
       db " ",13,10
       db " ",13,10
       db "                                  ENTER CHOICE: $"
      tcw  db "Turning clockwise       $"
      tccw db "Turning counterclockwise $"
      tcont db "Turn continuously $"
      tman db "Turn manually     $"
      
      
      pkey db "press any key...$"
      ends
      
      stack segment
      dw 128 dup(0)
      ends
      
      code segment
      start:
      ; set segment registers:
      mov ax, data
      mov ds, ax
      mov es, ax
      
      
      setup:    
      mov si, 0     ;index for left move
      mov di, 0     ;index for right move
      call blubox   ;sets up the screen with menu
      
      MOV AL, 02H   ;TURN MIDDLE MAGNET ON
      OUT 7, AL
      
      functionator:
      
      CALL KEYPRESS ;check if key has been pressed
      CALL MOUSEGRAB
      
      JMP functionator
      
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;CHECKS THE DEGREES OF THE STEPPER;;;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      CHECKDEGREES PROC NEAR
          PUSH SI
          PUSH DI
      
          CMP SI, DI            ;CHECKS IF 0 DEGREES
          JE ZERO
          JG LEFTDEGREE         ;STEPPER IS ON LEFT HALF, CHECK DEGREES THERE
      
          SUB DI, SI
          SHL DI, 1     
          MOV BX, 64
          SUB BX, DI
          MOV DI, BX
      
          MOV AX, ANGLE[DI]
      
      
          OUT 199, AX
          JMP DONEDEGREE
      
          LEFTDEGREE:
          SUB SI, DI
          SHL SI,1
      
          MOV AX, ANGLE[SI]
      
          OUT 199, AX
          JMP DONEDEGREE
      
          ZERO:     
          XOR AX, AX
          OUT 199, AX
      
          DONEDEGREE:
          POP DI
          POP SI
      
          RET
      CHECKDEGREES ENDP
      
      ;;;;;;;;;;;;;;;;;;;;;;
      ;RESTARTS THE STEPPER;
      ;;;;;;;;;;;;;;;;;;;;;;
      RESETIT PROC NEAR
      push ax
      push bx
      push cx
      resetstep:
      
      CMP SI, DI
      JE DONERESET
      JG LEFTCOMMAND
      
      RIGHTCOMMAND:
      SUB DI, SI
      MOV CX, DI
      GORIGHT1:
      CALL DELAY
      CALL MOVERIGHT
      CMP CX, 1
      JE DONERESET
      DEC CX
      JMP GORIGHT1
      
      JMP DONERESET
      
      LEFTCOMMAND:
      SUB SI, DI
      MOV CX, SI
      GOLEFT1:
      CALL DELAY
      CALL MOVELEFT
      CMP CX, 1
      JE DONERESET
      DEC CX
      
      JMP GOLEFT1
      
      
      DONERESET:
      MOV SI, 0H
      MOV DI, 0H
      
      POP CX
      POP BX
      POP AX
      
      RET
      RESETIT ENDP
      
      
      ;;;;;;;;;;;;;;;;;;;;;
      ;creates a delay;;;;;
      ;;;;;;;;;;;;;;;;;;;;;
      delay proc near
      
      
      mov ax, 5    
      countit:
      
      
      cmp ax, 0
      je donedelay
      dec ax
      jmp countit
      
      donedelay:
      
      ret
      delay endp
      
      
       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       ;moves the stepper to the LEFT;;
       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
       MOVERIGHT PROC NEAR
        IN AL, 7
      
      
        CMP AL, 81H   ;IF RIGHTMOST MAGNET IS ON, TURN
        JE RIGHT2     ;TWO LEFTMOST MAGNETS ON
      
        CMP AL, 82H   ;IF MIDDLE MAGNET IS ON,
        JE RIGHT1     ;TURN ON TWO RIGHTMOST MAGNETS
      
        CMP AL, 83H   ;IF TWO RIGHTMOST MAGNETS ARE ON,
        JE RIGHT3      ;TURN ON THE RIGHTMOST MAGNET
      
        CMP AL, 84H   ;IF ONE LEFTMOST MAGNET IS ON,
        JE RIGHT2      ;TURN ON TWO LEFTMOST MAGNETS
      
        CMP AL, 86H   ;IF TWO LEFTMOST MAGNETS ARE ON,
        JE RIGHT4      ;TURN MIDDLE MAGNET ON
      
      
      
        RIGHT1:
        MOV AL, 03H   ;TURN ON THE TWO RIGHT MAGNETS
        OUT 7, AL     ;FOR A HALFSTEP TO THE RIGHT
        JMP DONERIGHT
      
        RIGHT2:
        MOV AL, 06H   ;TURN THE TWO LEFTMOST MAGNETS ON
        OUT 7, AL     ;FOR A HALFSTEP TO THE RIGHT
        JMP DONERIGHT
      
        RIGHT3:
        MOV AL, 01H   ;TURN RIGHTMOST MAGNET ON
        OUT 7, AL     ;FOR FULL STEP TO RIGHT
        JMP DONERIGHT                                   
      
        RIGHT4:
        MOV AL, 02H   ;TURN MIDDLE MAGNET ON FOR
        OUT 7, AL     ;FULL STEP TO RIGHT
      
        DONERIGHT:
        CMP SI, 20H
        JE RESETSI
        inc SI
        JMP FINALRIGHT
      
        RESETSI:
        MOV SI, 1H
      
        FINALRIGHT:
        CALL checkdegrees
      RET
      MOVERIGHT ENDP
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;moves the stepper to the right;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      MOVELEFT PROC NEAR
        IN AL, 7
      
        CMP AL, 86H   ;IF TWO LEFT MAGNETS ARE ON,
        JE LEFT2      ;TURN LEFTMOST MAGNET ON
      
        CMP AL, 84H   ;IF ONE LEFTMOST MAGNET IS ON,
        JE LEFT3      ;TURN ON TWO RIGHTMOST MAGNETS ON
      
        CMP AL, 83H   ;IF TWO RIGHTMOST MAGNETS ARE ON,
        JE LEFT4      ;TURN ON MIDDLE MAGNET
      
        CMP AL, 82H   ;IF MIDDLE MAGNET IS ON,
        JE LEFT1      ;TURN ON TWO LEFTMOST MAGNETS
      
        CMP AL, 81H   ;IF RIGHTMOST MAGNET IS ON, TURN
        JE LEFT3      ;TWO RIGHTMOST MAGNETS  
      
        LEFT1:
        MOV AL, 06H   ;TURN ON THE TWO LEFT MOTORS
        OUT 7, AL     ;FOR A HALFSTEP TO THE LEFT
        JMP DONELEFT
      
        LEFT2:
        MOV AL, 04H   ;TURN THE LEFTMOST MAGNET ON
        OUT 7, AL
        JMP DONELEFT
      
        LEFT3:
        MOV AL, 03H   ;TURN TWO RIGHTMOST MAGNETS ON
        OUT 7, AL
        JMP DONELEFT                                   
      
        LEFT4:
        MOV AL, 02H   ;TURN MIDDLE MAGNET ON
        OUT 7, AL   
      
        DONELEFT:
        CMP DI, 20H
        JE RESETDI    ;when
        inc DI
        JMP FINALLEFT
      
        RESETDI:
        MOV DI, 1H
      
        FINALleft:
        CALL CHECKDEGREES
      RET
      MOVELEFT ENDP
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;CHECKS IF MOUSE HAS BEEN PRESSED;;;;;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      MOUSEGRAB PROC NEAR    
      PUSH CX
      PUSH BX
      
      MOV AX, 01H        ;DISPLAY CURSOR
      INT 33H
      MOV AX, 03H        ;FIND OUT THE BUTTON PRESS
      INT 33H            
      CMP BX, 01H         ;IF MOUSE NOT PRESSED, JUMP OUT
      JE GOMOUSE
      POP BX
      POP CX
      JMP MOUSEDONE
      
      GOMOUSE:
      CMP DX, 20H
      JL MOUSEDONE
      
      CMP DX, 28H
      JL RESETMOUSE
      
      CMP DX, 30H
      JL DIRECTMOUSE
      
      CMP DX, 38H
      JL INPUTMOUSE
      
      CMP DX, 40H
      JL TURNMOUSE
      
      CMP DX, 48H
      JL RIGHTMOUSE
      
      CMP DX, 50H
      JL LEFTMOUSE
      
      CMP DX, 58H
      JG MOUSEDONE
      
      
      DIRECTMOUSE:
      POP BX
      POP CX
      CALL DIRECT
      JMP MOUSEDONE
      
      INPUTMOUSE:
      POP BX
      POP CX
      CALL ENTER
      JMP MOUSEDONE
      
      TURNMOUSE:
      POP BX
      POP CX
      CMP BH, 1
      JE CONT_TURN_MOUSE
      JMP MOUSEDONE
      
      RIGHTMOUSE:
      POP BX
      POP CX
      CALL MOVERIGHT
      JMP MOUSEDONE
      
      LEFTMOUSE:
      POP BX
      POP CX
      CALL MOVELEFT
      JMP MOUSEDONE
      
      CONT_TURN_MOUSE:
      CMP BL, 1
      JE TURNCLOCK_MOUSE
      CALL TURNCCW
      JMP MOUSEDONE
      
      TURNCLOCK_MOUSE:
      CALL TURNCW
      JMP MOUSEDONE
      
      RESETMOUSE:
      POP BX
      POP CX
      CALL RESETIT
      
      MOUSEDONE:
      
      RET
      MOUSEGRAB ENDP
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;CHECKS TO SEE IF KEY HAS BEEN PRESSED;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      KEYPRESS PROC NEAR
      
      
      MOV AH, 1H        ;CHECKS IF KEY IS IN BUFFER
      INT 16H
      JZ DONE
      
      mov ah, 0h        ;MOVES PRESS FROM BUFFER
      int 16h
      
      CMP AH, 10H       ;IF Q, THEN QUIT
      JE FINISH
      
      CMP AL, 34H       ;if 4, turn (only if continuous)
      JE TURNIT    
      
      CMP AH, 4BH       ;if <- then move left
      JE GOLEFT
      
      CMP AH, 4DH       ;if -> then move right
      JE GORIGHT
      
      CMP AL, 31H       ;if 1 then reset
      JE GORESET
      
      CMP AL, 32H       ;if 2, select clockwise or counter
      JE DIRECTION
      
      CMP AL, 33H       ;if 3, select continuous or manual
      JE INPUT
      
      
      
      
      JMP DONE
      
      
      INPUT:
      CALL ENTER
      JMP DONE
      
      TURNIT:
      CMP BH, 1
      JE  CONTINUOUSTURN
      JMP DONE
      
      DIRECTION:
      CALL DIRECT
      JMP DONE
      
      GOLEFT:
      CALL MOVELEFT
      JMP DONE
      
      GORIGHT:
      CALL MOVERIGHT
      JMP DONE
      
      GORESET:
      CALL RESETIT
      JMP DONE
      
      CONTINUOUSTURN:
      CMP BL, 1
      JE TURNCLOCK
      CALL TURNCCW
      JMP DONE
      
      TURNCLOCK:
      CALL TURNCW
      
      DONE:
      RET
      KEYPRESS ENDP
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;TURNS CONTINUOUSLY CLOCKWISE;;;;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      TURNCW PROC NEAR
      TURNCWLOOP:
      CALL MOVELEFT
      CALL DELAY
      
      MOV AH, 1H        ;CHECKS IF KEY IS IN BUFFER
      INT 16H                                      
      JNZ doneturning
      
      PUSH CX
      PUSH BX
      MOV AX, 03H        ;FIND OUT THE MOUSE PRESS
      INT 33H            
      CMP BX, 01H         ;IF MOUSE NOT PRESSED, JUMP OUT
      POP BX
      POP CX    
      JNE TURNCWLOOP                                      
      
      doneturning:
      
      RET
      TURNCW ENDP
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;TURNS CONTINUOUSLY COUNTERCLOCKWISE;;;;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      TURNCCW PROC NEAR
      TURNCCWLOOP:
      CALL MOVERIGHT
      CALL DELAY
      
      MOV AH, 1H        ;CHECKS IF KEY IS IN BUFFER
      INT 16H       
      JNZ doneturningccw
      
          PUSH CX
      PUSH BX
      MOV AX, 03H        ;FIND OUT THE MOUSE PRESS
      INT 33H            
      CMP BX, 01H         ;IF MOUSE NOT PRESSED, JUMP OUT
      POP BX
      POP CX
      JNE TURNCCWLOOP
      
      doneturningccw:
      RET
      TURNCCW ENDP
      
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;DETERMINES IF CONTINUOUS OR MANUAL;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      ENTER PROC NEAR
      PUSH BX
      MOV AH, 02H           ;moves cursor to letter
      MOV BH, 0H            ;after "Turn"
      MOV DH, 11H           
      MOV DL, 5
      INT 10H
      
      MOV AH, 08H           ;OBTAIN THE LETTER IN AL
      MOV BH, 0H
      INT 10H
      
      MOV AH, 02H           ;moves cursor to print new
      MOV BH, 0H            ;string
      MOV DH, 11H            
      MOV DL, 0H
      INT 10H
      
      POP BX
      
      CMP AL, 'c'           ;CHECK IF CONTINOUS
      JE MANTURN
      
      MOV AH, 09H           ;print "turn continuously"
      MOV DX, OFFSET tcont
      INT 21H
      
      MOV BH, 1             ;index for moving motor
      
      JMP DONEENTER  
      
      MANTURN:
      
      MOV AH, 09H
      MOV DX, OFFSET tman   ;print "turn manual"
      INT 21H
      
      MOV BH, 0
      
      doneenter:    
      
      RET
      ENTER ENDP
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;CHECKS CURRENT DIRECTION THEN CHOOSES THE NEW ONE;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      DIRECT PROC NEAR
      PUSH BX
      
      MOV AH, 02H           ;moves cursor to letter
      MOV BH, 0H            ;after "C" in either clockwise
      MOV DH, 10H            ;or counterclockwise
      MOV DL, 9
      INT 10H
      
      MOV AH, 08H           ;OBTAIN THE LETTER IN AL
      MOV BH, 0H
      INT 10H
      
      MOV AH, 02H           ;moves cursor to print new
      MOV BH, 0H            ;string
      MOV DH, 10H            
      MOV DL, 0H
      INT 10H
      
      POP BX
      
      CMP AL, 'l'           ;CHECK IF CLOCKWISE
      JE CCWCOUNT
      
      MOV AH, 09H           ;print "turning clockwise"
      MOV DX, OFFSET tcw
      INT 21H
      
      MOV BL, 1             ;index for moving motor
      
      JMP DONEDIRECT  
      
      CCWCOUNT:
      
      MOV AH, 09H
      MOV DX, OFFSET tccw   ;print "turning ccw"
      INT 21H
      
      MOV BL, 0
      
      donedirect:
      ret
      DIRECT ENDP
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;CREATES BLUE BACKGROUND;;;;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      BLUBOX PROC NEAR
      MOV AH, 7H          ;creates a blue background         
      MOV AL, 0H
      MOV BH, 1EH
      MOV CH, 0H
      MOV CL, 0H
      MOV DH, 24
      MOV DL, 79
      INT 10H
      
      
      MOV AH, 02H           ;moves cursor for menu
      MOV BH, 0H  
      MOV DH, 2H
      MOV DL, 25H
      INT 10H
      
      MOV AH, 09            ;PRINTS "MENU"
      MOV DX, OFFSET MENU
      INT 21H
      
      
      
      RET
      BLUBOX ENDP
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;clears the screen;;;;;;;;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      CLEARSCREEN PROC NEAR
      
      MOV AH, 06H                   ;clear screen
      MOV AL, 0
      MOV BH, 7
      MOV CH, 0
      MOV CL, 0
      MOV DH, 24
      MOV DL, 79
      INT 10H
      
      MOV AH, 02H                   ;moves the cursor
      MOV BH, 0H
      MOV DH, 0H
      MOV DL, 0H
      INT 10H
      
      RET
      CLEARSCREEN ENDP
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;program is finished;;;;;;;;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      
      FINISH:  
      
      call clearscreen    
      
      
      lea dx, pkey
      mov ah, 9
      int 21h        ; output string at ds:dx
      
      ; wait for any key....    
      mov ah, 1
      int 21h
      
      mov ax, 4c00h ; exit to operating system.
      int 21h    
      ends
      
      end start ; set entry point and stop the assembler.
      [align=center][/align]

      نظر

      صبر کنید ..
      X