CIS-261 Home http://www.c-jump.com/bcc/

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_prototype.asm
  7. Notes regarding the Beep sample program
  8. Portability Concerns
  9. The Assignment

1. Getting Started




; CIS-261
; 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



; CIS-261 Lab exercise M09
; M09_prototype.asm
; 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     ; takes 2 DWORD parameters
EXTERN _Sleep@4:NEAR    ; takes 1 DWORD parameter

.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, 500    ; duration, milliseconds
    push    eax
    mov     eax, 1000   ; frequency, Hertz
    push    eax
    call    _Beep@8     ; Beep( frequency, duration );

    mov     eax, 500    ; sleep time in milliseconds
    push    eax         ; param on the stack
    call    _Sleep@4
    
    ret
_main ENDP

END _main   ; Marks the end of the module and sets the program entry point label

5. Notes regarding the Beep sample program



6. Portability Concerns



7. The Assignment