Author Topic: Guess what: Another simple program!  (Read 199 times)

felipe

  • Member
  • ***
  • Posts: 282
  • I love assembly language programming.
Guess what: Another simple program!
« on: May 17, 2017, 02:45:10 AM »
The program would check if the beep in your machine is turned off or on. Then you can decide if to turn off, turn on or do no change. So, run the program as necessary  to configure the beep and to check for your self if the configuration was applied.   8)

Code: [Select]
.386
.model  flat,stdcall
option  casemap:none

include c:\masm32\include\windows.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\user32.inc

includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\user32.lib

.data?
on_OR_off       dword   ?

.data
title_program   byte    'BEEP CHECKER',0
content_welcome byte    'This program would let you',0ah,0dh
                byte    'check if the beep in your machine is on or off.',0ah,0dh
                byte    'Then you can change this setting as you wish.',0
content_off_?   byte    'The beep is turned on.',0ah,0dh
                byte    'Do you wish to turn off the beep?',0
content_on_?    byte    'The beep is off.',0ah,0dh
                byte    'Do you wish to turn the beep on?',0   
         
.code
start:
        push    MB_OK                           ; Welcome message.
        push    offset title_program
        push    offset content_welcome
        push    0
        call    MessageBox
       

        push    SPIF_UPDATEINIFILE              ; Test for beep if is on or off.
        push    offset on_OR_off
        push    0
        push    SPI_GETBEEP
        call    SystemParametersInfo


        cmp     on_OR_off,TRUE                     
        jne     not_active                      ; If is off we ask the user if he want to turn the beep on.

        push    1000                            ; Is on, so we make a beep showing the user that fact.
        push    580
        call    Beep

        push    MB_OKCANCEL                     ; Then we ask the user if he wants to turn the beep off.
        push    offset title_program
        push    offset content_off_?
        push    0
        call    MessageBox

        cmp     eax,IDOK                       
        je      turn_off
        jmp     the_end                         ; If he say no the program finish.

turn_off:
        push    SPIF_UPDATEINIFILE              ; We turn off the beep like the user wants.
        push    0
        push    FALSE
        push    SPI_SETBEEP
        call    SystemParametersInfo
        jmp     the_end
   
not_active:
        push    MB_OKCANCEL                     ; Is off so we ask the user if he want to turn on.
        push    offset title_program
        push    offset content_on_?
        push    0
        call    MessageBox

        cmp     eax,IDOK
        je      turn_on                         
        jmp     the_end                         ; If the user say no the program finish.

turn_on:
        push    SPIF_UPDATEINIFILE
        push    0
        push    TRUE
        push    SPI_SETBEEP
        call    SystemParametersInfo
       
the_end:
        push    0
        call    ExitProcess

        end     start
Felipe.

jj2007

  • Member
  • *****
  • Posts: 7557
  • Assembler is fun ;-)
    • MasmBasic
Re: Guess what: Another simple program!
« Reply #1 on: May 17, 2017, 03:16:01 AM »
Congrats, the parameter count seems correct this time :t

Code: [Select]
        cmp     eax,IDOK
        je      turn_on                         
        jmp     the_end                         ; If the user say no the program finish.

turn_on:

Better:
Code: [Select]
        cmp     eax,IDOK
        jne     the_end                         ; If the user say no the program finish.

turn_on:

felipe

  • Member
  • ***
  • Posts: 282
  • I love assembly language programming.
Re: Guess what: Another simple program!
« Reply #2 on: May 17, 2017, 04:28:00 AM »
Thanks JJ! You are right about that optimization, thanks a lot!  :icon_mrgreen:
Felipe.