CIS-77 Home http://www.c-jump.com/CIS77/CIS77syllabus.htm

Lab M09. Data Arrays, Windows API Calls


  1. Getting Started
  2. add_16_bytes.ASM
  3. Beep API Call
  4. Beep Error Codes
  5. Calling Beep from Assembly
  6. M09.ASM
  7. Notes regarding the Beep sample program
  8. Portability Concerns
  9. The Assignment

1. Getting Started




; CIS-77
; add_16_bytes.asm
;
.586P
.MODEL FLAT         ; Flat memory model
option casemap:none ; Treat labels as case-sensitive

.CONST          ; Constant data segment

.STACK 100h     ; (default is 1-kilobyte stack)

.DATA           ; Begin initialized data segment
    values db 16 DUP( 5 ) ; 16 bytes of values "5"

; Code segment
.CODE           ; Begin code segment
_main PROC      ; Beginning of code

    mov eax, 0      ; clear result 
    mov bl, 16      ; init loop counter 
    lea esi, values ; init data pointer
addup:
    add al, [esi]   ; add byte to sum
    inc esi         ; increment data pointer 
    dec bl          ; decrement loop counter 
    jnz addup       ; if BL not zero, continue
    mov [esi], al   ; save sum 
    ret             ; Exit
    
_main ENDP
END _main       ; Marks the end of the module and sets the program entry point label

2. Beep API Call



3. Beep Error Codes



4. Calling Beep from Assembly



; @goto masm

; CIS-77 Lab exercise M09
; M09.BAT
; Program that beeps
;

.386                ; Tells MASM to use Intel 80386 instruction set.
.MODEL FLAT         ; Flat memory model
option casemap:none ; Treat labels as case-sensitive

EXTERN _Beep@8:NEAR

.CONST          ; Constant data segment

.DATA           ; Begin initialised data segment

.CODE           ; Begin code segment
_main PROC      ; Main entry point into program

    ; __stdcall calling convention: args pushed R to L
    
    mov         eax, 200  ; duration, milliseconds
    push        eax
    
    mov         eax, 1000 ; frequency, Hertz
    push        eax
    
    call        _Beep@8   ; Beep( frequency, duration );
    
    ret
_main ENDP
END _main       ; Marks the end of the module and sets the program entry point label

:masm
; @call "C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
; @echo ___________________________________________________
; ml /c /coff M09.BAT
; @echo ___________________________________________________
; link /subsystem:console /entry:main /out:M09.exe M09.OBJ kernel32.lib
; @echo ___________________________________________________
; @pause

5. Notes regarding the Beep sample program



6. Portability Concerns



7. The Assignment