Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Assembly language tutorial in debug and tasm

jdabs666

Recruit
Basic Member
Messages
3
Reaction score
0
Points
16
Introduction to Machine Language

DEBUG

A software that is classifies as debugger which is used for testing and debugging executable programs
Advantages
It is Free
It is universally available
It is simple to use
It requires relatively little memory

DEBUG COMMANDS

E (Enter)
-enable you to key in data or machine instruction into memory beginning at a specific location address.
E.g -E 0200

D (Display or Dump)
Displays the contents of a portion memory ni hex and ASCII forms starting with the given address
E.g. -D 0200

A (Assemble)
Allows you to create a program in mnemonic or symbolic code.
E.g. -A 0100

T (Trace)
Runs he program in single-step mode. It also displays the new values of the registers and the next instruction to be executed.
E.g -T

G (Go)
Runs the program as a whole in memory an displays the output
E.g. -G

U (Unassemble)
Lists all the instructions contained in the program beginning at the given address. You can also specify the last address location.
E.g. -U 0100
-U 0100 0109

N (Name)
Gives a name to your program, coded as N <path> <filename>
Extention nae is .COM
E.g. -N A:SAMPLE.COM

W (Write)
Saves the program onto disk storage
E.g. -W

BASIC ASSEMBLY INSTRUCTIONS USED IN DEBUG

MOV (Move Data)
Copies and transfers data between two registers, or between an immediate data to a register
Format: MOV <register>, <register>
MOV <register>, <immediate data>
Example: MOV AX, BX
MOV CX, 5083
MOV CL, DL
MOV BL, 33

ADD (Add Data)
Used to get the sum of two registers or a register and an immediate data, and stores the result to the left most register
Format: ADD <register>, <register>
ADD <register>, <immediate data>
Example: ADD CX, BX
ADD AX, 0308
ADD AL, BL
ADD DH, 85

MUL (Multiply Data)
It is used to get the product of a given register and AX register, and stores the result to AX register. If the product is greater than 16 bits, the overflow is stored in DX register.
Format: MUL <register>
Example: MUL CX

DIV (Divide Data)
Used to divide the value of a given register and AX register, stores the quotient to AX and the remainder to DX registers respectively
Format: DIV <register>
Example DIV BX

INC (Increment by One)
Used to increase the value of the register by one (1).
Format: INC register
Example: INC AX
INC CH

DEC (Decrement by One)
Opposite of INC, decreases the value of the register by one (1).
Format: DEC <register>
Example: DEC AX
DEC CH

LOOP (Loop Until Complete)

It controls the execution of a program segment in a specified number of times.
The CX register should contain a count value before starting the loop and automatically decrements by one (1)
If CX is not equal to zero (0), it transfers to its operand address which points to the start of the loop; otherwise it drops to the nest instruction.
Format: LOOP <offset address>
Example: LOOP 0108


CODING ASSEMBLY LANGUAGE IN TASM

Comment

Ignored by the assembler.
Can improve program’s readability and clarity
Begins with a semicolon (;)
Ways to include comment
Any statement whose first non-block character is a semicolon
Example:
; This program displays Hello, World!
At the end of an instruction
Example:
MOV AX, 8053H ;initializes the value of AX to 8053

Reserved Words

Words in which the assembler assigns a special meaning and it cannot be used as identifiers
Using reserved words for a wrong purpose causes the assembler to generate an error message

Categories of reserved words

Instructions
Statements that will be translated into machine language and executed by the computer.
Examples:
MOV ADD SUB
MUL DIV INC
DEC LOOP CMP


Directives
Statements that give information to the assembler
Sometimes called pseudo-ops
Examples:
TITLE DOSSEG .MODEL
.STACK .DATA .CODE

Rules in Constructing Valid identifier

It must use letters (A...Z, a…z), number (0…9) and/or special characters like underscore (_), question mark (?) and at sign (@).
It must always start with a letter
It must not use reserved words
It must not exceed to 31 character.
Examples of valid identifiers:
neym r2d2
num_1 msg8
Examples of invalid identifiers:
title num-1
4ever

Statement
May begin anywhere on the line
Each line can only contain one statement
Assembly is not case sensitive
Examples:
ADD AX, BX ; uses 2 operands
DEC CX ; uses
RET ; no operand

Most common directives

TITLE

It creates a title (up to 60 characters) of a source listing.
Format:
TITLE <TEXT>
Examples:
TITLE This program displays Kumusta, BUPC!
TITLE PROGRAM1.ASM

.MODEL

It specifies and initializes the memory model before defining any segment
Format:
.MODEL <memory-model>
Examples:
.MODEL TINY
.MODEL SMALL
.MODEL MEDIUM

.STACK

It defines the size of the attack. The default stack size is 1,024 bytes which you can overrule.
Format:
.STACK <size>
Example:
.STACK 0100h

.DATA

It defines and marks the beginning of data segment
Format:
.DATA
Example:
.DATA

.CODE

It defines and marks the code segment which consists of a set of instructions.
Format:
.CODE
Example:
.CODE

START:

Defines the start of program execution
Format:
START:
Examples:
START:

END

It is placed at the last line of the source code
Format:
END
Example:
END START

STRING

Used for descriptive data such as person’s name or simply a message.
It must end with dollar ($) symbol and defined in double quotation marks (“ “).
DB is the conventional format for defining string of any length.
Example:
neym db “Louis Vuitton$”

Numeric Constant

Used to define arithmetic values and memory address.
It is defined with a radix specifier such as d for decimal, b for binary and h for hexadecimal.
Example:
msg db “Bon jour, monsieur!”, 0Ah, 0Dh, “$”
msg db “Bon jour, monsieur!”, 10d, 13d, “$”
msg db “Bon jour, monsieur!”, 00001010b, 00001101b, “$”

Screen Processing

The monitor
A typical video screen has 80 columns numbered form 0 to 79 and 25 rows numbered from 0 to 24.

Clearing the screen in Assembly Approach

Interrupt 10h and function 06h handles the process of clearing the screen and scrolling
Clear all or part of display beginning at any screen location and ending at any higher-numbered location.

Sample code shows how to clear screen code in assembly

MOV AX, 0600h ; AH = 00h (scroll), AL, 00h (Full screen)
MOV BH, 07h ; 0 (BLACK BACKGROUND), 7 (WHITE TEXT COLOR)
MOV CX, 0000h ; CH = 00H (ROW), CL, 00H (COLUMN)
MOV DX, 184Fh ; DH = 18H (ROW), DL=4FH (COLUMN)
INT 10h ; CALL INTERRUPT SERVICE

SETTING THE CURSOR FUNCTION


Interrupt 10h is the BIOS operation for screen handling and function 02h tells the operation to set the cursor
Its position determines where the next character is to be displayed.

MOV AH, 02H ; REQUEST TO SET THE CURSOR POSITION
MOV BH, 00H ; PAGE NUMBER 0
MOV DH, 0AH ; ROW - 10 IN DECIMAL
MOV DL, 08H ; COLUMN = 8 IN DECIMAL
INT 10H

MAY CONTINUATION PA PO ITO, WAIT NYO LANG

Press thanks kung nakatulong,

Accepting Requests for Tutorial in any Programming Languages
 
Last edited:
sir pano loop na pababa??
dba sa C programming gotoxy tapos horizontal point ay X
tapos sa vertical point ay Y.
pano loopings sa TASM


plss help.:praise:


:thanks:
 
hehe patulong dn po..
sino po ang meron
ng assembly language programming codes?
aamh game codes po..

please hehe..
kelangan kasi para sa project eeh..
yung simple lang ba bsta .ASM file type cya

khit links nlang po s net or kung meron kyo please
share naman po oooh..

:pray::pray::pray:
 
hehe patulong dn po..
sino po ang meron
ng assembly language programming codes?
aamh game codes po..

please hehe..
kelangan kasi para sa project eeh..
yung simple lang ba bsta .ASM file type cya

khit links nlang po s net or kung meron kyo please
share naman po oooh..

:pray::pray::pray:

Code:
 .486
  .model flat, stdcall
  option casemap :none
 
;===============standard headers=============
  include \masm32\include\windows.inc
  include \masm32\macros\macros.asm
 
;===============minimal headers===============
  include \masm32\include\masm32.inc
  include \masm32\include\user32.inc
  include \masm32\include\gdi32.inc
  include \masm32\include\kernel32.inc
 
;============minimal libarys===============
  includelib \masm32\lib\masm32.lib
  includelib \masm32\lib\user32.lib
  includelib \masm32\lib\gdi32.lib
  includelib \masm32\lib\kernel32.lib
 
.code             ;here the code starts
 
start:            ;the entry point of the programm
 
  call main       ;call the main PROCedure
 
  exit            ;exit process
 
 rand PROC i:DWORD
    push edx
    mov edx, 0
    invoke GetTickCount
    mov edi, i
    div edi
    mov eax, edx
    pop edx
    ret
   rand endp  
 
main proc
  LOCAL liczba:DWORD
  LOCAL str1:DWORD
  LOCAL wynik:DWORD
  print chr$("where gonna play a game -->;;; guess the number!!!", 13, 10)
 
  invoke rand, 200
  mov wynik, eax  
 
  game:
    print chr$(" ",13,10)
    mov str1, input("please enter a positive number below 200: ") ;ask for input
    mov liczba, sdword$(str1)     ;convert from string to unsigned int
   
    cmp liczba, wynik       ;compare the "int1" number with "6"
    je equel          ;if comparisation was equell jump to "equel"
    jg greater        ;if comparisation was greater jump to "greater"
    jl lesser         ;if comparisation was lesser jump to "lesser"
 
  equel:
    print chr$("    CORRECT!!!!",13,10)
    jmp done
   
  greater:
    print chr$("    Your guess was to high", 13, 10)
    jmp game
 
  lesser:
    print chr$("    Your guess was to low", 13, 10)
    jmp game
 
  done:
    ret
 
main endp
 
end start

Ito try mo na lang ala akung Tasm di ko ma run napulot ko lang din yan.:thumbsup:
 
Code:
 .486
  .model flat, stdcall
  option casemap :none
 
;===============standard headers=============
  include \masm32\include\windows.inc
  include \masm32\macros\macros.asm
 
;===============minimal headers===============
  include \masm32\include\masm32.inc
  include \masm32\include\user32.inc
  include \masm32\include\gdi32.inc
  include \masm32\include\kernel32.inc
 
;============minimal libarys===============
  includelib \masm32\lib\masm32.lib
  includelib \masm32\lib\user32.lib
  includelib \masm32\lib\gdi32.lib
  includelib \masm32\lib\kernel32.lib
 
.code             ;here the code starts
 
start:            ;the entry point of the programm
 
  call main       ;call the main PROCedure
 
  exit            ;exit process
 
 rand PROC i:DWORD
    push edx
    mov edx, 0
    invoke GetTickCount
    mov edi, i
    div edi
    mov eax, edx
    pop edx
    ret
   rand endp  
 
main proc
  LOCAL liczba:DWORD
  LOCAL str1:DWORD
  LOCAL wynik:DWORD
  print chr$("where gonna play a game -->;;; guess the number!!!", 13, 10)
 
  invoke rand, 200
  mov wynik, eax  
 
  game:
    print chr$(" ",13,10)
    mov str1, input("please enter a positive number below 200: ") ;ask for input
    mov liczba, sdword$(str1)     ;convert from string to unsigned int
   
    cmp liczba, wynik       ;compare the "int1" number with "6"
    je equel          ;if comparisation was equell jump to "equel"
    jg greater        ;if comparisation was greater jump to "greater"
    jl lesser         ;if comparisation was lesser jump to "lesser"
 
  equel:
    print chr$("    CORRECT!!!!",13,10)
    jmp done
   
  greater:
    print chr$("    Your guess was to high", 13, 10)
    jmp game
 
  lesser:
    print chr$("    Your guess was to low", 13, 10)
    jmp game
 
  done:
    ret
 
main endp
 
end start

Ito try mo na lang ala akung Tasm di ko ma run napulot ko lang din yan.:thumbsup:

aah sir..meron kpa po b?
saan m po npulot?
 
BTW, that would need a different type of Assembler (MASM) so di yan pwedeng i-assemble sa TASM.

Another note is that it's Windows, so kung TASM gamit mo malamang na DOS programming kayo.

Eto puro dos based stuff:

http://jafile.com/uploads/relminator/asmsamples.zip

sir..games dn po b to?dko pa po matry eeh..64bit kc laptop ko so dko cya magagamit..pang 32bit lang kc ang tasm assembler
 
Bakit po di mo ba yan gusto games din aman yan diba hanap ka po kay Mr.Google andami nyang ganyan ano po ba ang output nyang codes na yan na run mo na ba?

:xmas::newyear:

gusto sir syempre..khit dko pa natry haha..
pero sir..
meron kpa b?pra naman po sna my choices ako..
namimili kasi ng iprepresent
ung instructor ko eeh..pang proj. po sna..

:thumbsup:
 
Snake​

Code:
    include '%fasmi%\win32ax.inc'
     
    section 'sjkdiu' code readable executable writeable
     
    gname db 'Snake From HELL',0
     
    gamespeed dd 55 ; This is our game loop delay
     
    applefile db 'apple.bmp',0
     
    struc _rect
    {
    .left dd 0
    .top dd 0
    .right dd 0
    .bottom dd 0
    }
    rect _rect
     
    startbonus dd 0
     
    start: ;CODE START ============================================
    push 'P'
    call [GetAsyncKeyState]
    invoke GetModuleHandle,0
    invoke LoadBitmap,eax,10
    push eax
    invoke GetDC,0
    invoke CreateCompatibleDC,eax
    pop ecx
    mov [mapple],eax
    invoke SelectObject,[mapple],ecx
    ;Create our DC
    call createmydc
     
    ;invoke CreateCompatibleDC,0
    ;push eax
    ;invoke CreateCompatibleBitmap,eax,250,30
    ;pop ecx
    ;push ecx
    ;invoke SelectObject,ecx,eax
    ;pop eax
    ;mov [mtext],eax
    ;invoke SetBkMode,[mdc],TRANSPARENT
    ;invoke SetTextColor,[mdc],0FFFFFFh
     
     
    invoke CreateSolidBrush,0FFFFFFh
    mov [clblack],eax
    invoke CreateSolidBrush,0208820h
    mov [clgray],eax
     
    invoke CreateThread,0,0,createwin,0,0,0
     
    invoke CreateThread,0,0,mainmenuproc,0,0,0
    invoke GetAsyncKeyState,VK_RETURN
    _main_menu:
     
    invoke GetAsyncKeyState,VK_RETURN
    test eax,eax
    jz notenter
     
    mov eax,[zmenuitem]
    cmp eax,0
    jne @f
    call _zeroall
    mov [startbonus],3
    mov [gamespeed],60
    call _game
    jmp notenter
    @@:
    cmp eax,1
    jne @f
    call _zeroall
    mov [startbonus],6
    mov [gamespeed],50
    call _game
    jmp notenter
    @@:
    cmp eax,2
    jne @f
    call _zeroall
    mov [startbonus],24
    mov [gamespeed],30
    call _game
    jmp notenter
    @@:
    cmp eax,3
    jne @f
    call _zeroall
    mov [startbonus],30
    mov [gamespeed],20
    call _game
    jmp notenter
    @@:
    cmp eax,4
    jne @f
    call _zeroall
    mov [startbonus],10
    mov [gamespeed],33
    mov [haswalls],1
    call _game
    jmp notenter
    @@:
    cmp eax,5
    jne @f
    call _zeroall
    mov [startbonus],8
    mov [gamespeed],25
    mov [haswalls],1
    call _game
    jmp notenter
    @@:
    cmp eax,6
    jne @f
    mov [exitgameflag],1
    @@:
     
    notenter:
     
    invoke Sleep,10
    mov eax,[exitgameflag]
    test eax,eax
    jz _main_menu
     
    ;call _zeroall
    ;call _game ;Start main game engine
     
    invoke ExitProcess,0DEADh
    exitgameflag dd 0
    isgaming dd 0
    retn ; Return of main program, this should not change at all...
    ;##############################################################
    createwin:
    invoke GetModuleHandle,0
    invoke DialogBoxParam,eax,37,HWND_DESKTOP,nullproc,0
    retn
    ;##############################################################
    ;##############################################################
    _game:
    mov [isgaming],1
    mov [snakesize],0
     
    mov [applex],0ffffh
    mov [appley],0ffffh
     
    invoke VirtualAlloc,0,500h,MEM_COMMIT,PAGE_READWRITE
    mov [snakebody],eax
     
    mov ecx,[startbonus]
    @@:
    push ecx
    call incsnake
    pop ecx
    loop @b
     
    mov eax,[snakebody]
    mov dword [eax],012c0190h
     
    mov [speedx],20
    mov [hasapple],0
     
    mov [myscore],0
    mov [dead],0
     
    invoke CreateThread,0,0,dprocedure,0,0,0
    _gameloop:
     
    mov al,[ispause]
    test al,al
    jnz @f
     
    call advsnake
    call fixrect   ;Is our snake in place o.o"?
    call makeapple ;We need an apple, dont?
    call gotapple  ;Did he got the damn apple?
    call isdead    ;Am i dead lol?
     
    mov al,[dead]
    test al,al
    jz @f
    mov [hasend],1
    @@:
     
    invoke Sleep,[gamespeed] ; Game SPEED
    ;The LOOP
    mov al,[hasend]
    test al,al
    jz _gameloop
     
    invoke DeleteDC,[mdc]
    call createmydc
    call scorescreen
    ;invoke inttohex,[myscore]
    ;invoke MessageBoxA,0,scorestr,'CarloS',30h
    mov [isgaming],0
    retn ;Return of GAME
     
    dprocedure:
    call dbackground ;First, we draw the BACKGROUND!
     
    invoke inttohex,[myscore]
    invoke TextOutA,[mdc],2,2,scorestr,32
     
    ;invoke BitBlt,[mdc],0,0,250,30,[mtext],0,0,SRCCOPY
     
    invoke BitBlt,[mdc],[applex],[appley],20,20,[mapple],0,0,SRCCOPY
    call dsnake
     
    mov al,[ispause]
    test al,al
    jz @f
    invoke TextOutA,[mdc],335,30,'GAME PAUSED',11
    @@:
     
    ;invoke BitBlt,[mdc],0,0,20,20,[mapple],0,0,SRCCOPY
    ;Write to OUR screen... lol
    invoke GetDC,0
    push eax
    invoke BitBlt,eax,0,0,800,600,[mdc],0,0,SRCCOPY
    pop eax
    invoke DeleteDC,eax
    call hotkeys    ;My hotkeys are set here =P
    invoke Sleep,8 ; "60 fps"? should be 16, but 12 is ok dont?
    mov al,[hasend]
    test al,al
    jz dprocedure
    retn
     
    ;Drawing functions #############$$$$$$$$$$$$$$$$$$$$$$$$$$$$
     
    dbackground:
    mov [rect.left],0
    mov [rect.top],0
    mov [rect.right],800
    mov [rect.bottom],600
    invoke FillRect,[mdc],rect,[clblack]
    retn
     
    dbackground2:
    mov [rect.left],0
    mov [rect.top],0
    mov [rect.right],800
    mov [rect.bottom],600
    invoke CreateSolidBrush,0h
    invoke FillRect,[mdc],rect,eax
    retn
     
    dsnake:
    mov eax,[snakesize]
    test eax,eax
    jz _dsnakeend
    mov ecx,eax
    @@:
    mov eax,4
    mul ecx
    add eax,[snakebody]
    sub eax,4
    mov dx,[eax]
    add eax,2
    mov ax,[eax]
    xchg ax,dx
    ; AX = Right word ; DX = Left word ; Y,X respectivamente
    movzx esi,ax
    mov [rect.left],esi
    add esi,20
    mov [rect.right],esi
    movzx esi,dx
    mov [rect.top],esi
    add esi,20
    mov [rect.bottom],esi
    push ecx
    invoke FillRect,[mdc],rect,[clgray]
    pop ecx
    loop @b
    _dsnakeend:
     
    retn
     
    hotkeys:
     
    invoke GetAsyncKeyState,VK_ESCAPE
    test eax,eax
    jz @f
    mov [hasend],1
    @@:
     
    invoke GetAsyncKeyState,VK_RIGHT
    test eax,eax
    jz @f
    mov ax,[speedy]
    test ax,ax
    jz @f
    mov [speedy],0
    mov [speedx],20
    @@:
    invoke GetAsyncKeyState,VK_LEFT
    test eax,eax
    jz @f
    mov ax,[speedy]
    test ax,ax
    jz @f
    mov [speedy],0
    mov [speedx],-20
    @@:
     
    invoke GetAsyncKeyState,VK_UP
    test eax,eax
    jz @f
    mov ax,[speedx]
    test ax,ax
    jz @f
    mov [speedx],0
    mov [speedy],-20
    @@:
    invoke GetAsyncKeyState,VK_DOWN
    test eax,eax
    jz @f
    mov ax,[speedx]
    test ax,ax
    jz @f
    mov [speedx],0
    mov [speedy],20
    @@:
    push 'P'
    call [GetAsyncKeyState]
    test eax,eax
    jz @f
    _not01:
    push 'P'
    call [GetAsyncKeyState]
    test eax,eax
    jnz _not01
    xor [ispause],1
    @@:
     
    retn
     
    incsnake:
    mov eax,[snakesize]
    inc eax
    mov ecx,4
    mul ecx
    sub eax,4
    add eax,[snakebody]
    mov dword [eax],0ffffffffh
    inc [snakesize]
    retn
     
    advsnake:
    mov ecx,[snakesize]
    mov eax,[snakebody]
    @@:
    mov eax,4
    mul ecx
    sub eax,4   ;Reach our spot
    test eax,eax
    jz @f       ;if our spot is 0, we dont need it anymore
    add eax,[snakebody]
    mov edx,eax
    sub edx,4   ;Lower body
    mov edx,dword [edx]
    mov dword [eax],edx
    loop @b
    @@:
    mov eax,[snakebody]
    mov dx,[speedx]
    add word [eax],dx
    add eax,2
    mov dx,[speedy]
    add word [eax],dx
    retn
     
    fixrect:
    mov eax,[haswalls]
    test eax,eax
    jnz _haswall
    mov eax,[snakebody]
    mov dx,[eax]
    add eax,2
    mov ax,[eax]
    ;DX = X ; AX = Y
    cmp dx,800
    jne @f
    mov ecx,[snakebody]
    mov word [ecx],0
    jmp _endfixrect
    @@:
    cmp dx,-20
    jne @f
    mov ecx,[snakebody]
    mov word [ecx],800
    jmp _endfixrect
    @@:
    cmp ax,600
    jne @f
    mov ecx,[snakebody]
    add ecx,2
    mov word [ecx],0
    jmp _endfixrect
    @@:
    cmp ax,-20
    jne @f
    mov ecx,[snakebody]
    add ecx,2
    mov word [ecx],600
    jmp _endfixrect
    @@:
    _endfixrect:
    retn
    _haswall:
    mov eax,[snakebody]
    mov dx,[eax];X
    add eax,2
    mov ax,[eax];Y
    cmp dx,800
    jne @f
    mov [dead],1
    @@:
    cmp ax,600
    jne @f
    mov [dead],1
    @@:
    cmp dx,-20
    jne @f
    mov [dead],1
    @@:
    cmp ax,-20
    jne @f
    mov [dead],1
    @@:
    retn
     
    makeapple:
    mov al,[hasapple]
    test al,al
    jnz @f
    mov ebx,20
    mov [hasapple],1
    call [GetTickCount]
    and eax,39
    mul ebx
    mov [applex],eax
    call [GetTickCount]
    and eax,29
    mul ebx
    mov [appley],eax
    @@:
    retn
     
    gotapple:
    xor edx,edx
    mov eax,[snakebody]
    mov dx,[eax]
    add eax,2
    mov ax,[eax]
    and eax,0ffffh
    cmp edx,[applex]
    jne @f
    cmp eax,[appley]
    jne @f
    mov [hasapple],0
    mov [applex],0ffffh
    call incsnake
    mov eax,70
    sub eax,[gamespeed]
    mul eax
    mov ecx,5
    ;mul ecx
    mov ecx,[snakesize]
    mul ecx
    mov ecx,[haswalls]
    inc ecx
    mul ecx
    add [myscore],eax
    @@:
    retn
     
    isdead:
    mov ecx,[snakesize]
    mov eax,[snakebody]
    xor edx,edx
    mov dx,[eax]
    add eax,2
    mov ax,[eax]
    and eax,0ffffh
    mov edi,edx
    mov ebx,eax ;At this rate, DI = X; BX = Y
    @@:
    mov eax,4
    mul ecx
    sub eax,4
    test eax,eax
    jz @f
    add eax,[snakebody]
    cmp di,[eax]
    jne _continue01
    add eax,2
    cmp bx,[eax]
    jne _continue01
    mov [dead],1
    _continue01:
    loop @b
    @@:
    retn
     
    _zeroall:
    mov ecx,_zend-_zstart-1
    @@:
    mov eax,_zstart
    add eax,ecx
    mov byte [eax],0
    loop @b
    retn
     
    createmydc:
    invoke GetDC,0
    invoke CreateCompatibleDC,eax
    mov [mdc],eax
    invoke GetDC,0
    invoke CreateCompatibleBitmap,eax,800,600
    mov [mbmp],eax
    invoke SelectObject,[mdc],[mbmp]
    invoke SetBkMode,[mdc],TRANSPARENT
    invoke SetTextColor,[mdc],0050588h
     
    retn
     
    zmenuitem dd 0
    mainmenuproc:
    mov eax,[isgaming]
    test eax,eax
    jnz _do023
     
    invoke GetAsyncKeyState,VK_ESCAPE
    test eax,eax
    jz @f
    invoke ExitProcess,0DEADh
    @@:
     
    invoke GetAsyncKeyState,VK_DOWN
    test eax,eax
    jz @f
    mov eax,[zmenuitem]
    cmp eax,6
    je @f
    inc [zmenuitem]
    _001:
    invoke GetAsyncKeyState,VK_DOWN
    test eax,eax
    jnz _001
    @@:
     
    invoke GetAsyncKeyState,VK_UP
    test eax,eax
    jz @f
    mov eax,[zmenuitem]
    test eax,eax
    jz @f
    dec [zmenuitem]
    _002:
    invoke GetAsyncKeyState,VK_UP
    test eax,eax
    jnz _002
    @@:
     
    call dbackground2
    invoke TextOutA,[mdc],150,50,'Snake from HELL III [ASM with COLORS = TOTAL WIN!]',50
     
    invoke TextOutA,[mdc],50,10,'Carlão o gostosão WINs!',23
     
    invoke TextOutA,[mdc],300,100+100-30,'Ramayan (gay) mode',18
    invoke TextOutA,[mdc],300,150+100-30,'I almost have balls',19
    invoke TextOutA,[mdc],300,200+100-30,'My cock kill people',19
    invoke TextOutA,[mdc],300,250+100-30,'Satan is my best friend',23
    invoke TextOutA,[mdc],300,300+100-30,'Damn im GOD! [Almost-Ultimate]',30
    invoke TextOutA,[mdc],300,350+100-30,'I am the devil itself [Ultimate]',33
    invoke TextOutA,[mdc],300,400+100-30,'Exit game',10
     
     
    mov [rect.left],270
    mov eax,[zmenuitem]
    mov ecx,50
    mul ecx
    add eax,200-30
    mov [rect.top],eax
    mov [rect.right],285
    add eax,15
    mov [rect.bottom],eax
    invoke CreateSolidBrush,0FFh
    invoke FillRect,[mdc],rect,eax
     
    invoke GetDC,0
    push eax
    invoke BitBlt,eax,0,0,800,600,[mdc],0,0,SRCCOPY
    pop eax
    invoke DeleteDC,eax
     
    _do023:
    invoke Sleep,16
    jmp mainmenuproc
     
    scorescreen:
    call dbackground2
    invoke inttohex,[myscore]
    invoke TextOutA,[mdc],300,200,scorestr,32
    invoke TextOutA,[mdc],300,400,'Press [ENTER] to go back to main menu, you asshole...',53
    mov eax,[gamespeed]
    cmp eax,20
    jne @f
    mov eax,[myscore]
    cmp eax,0500000h
    jng @f
    invoke TextOutA,[mdc],300,200,'Lol, you ate satan''s balls 4 breakfast...',42
    @@:
     
    invoke GetDC,0
    push eax
    invoke BitBlt,eax,0,0,800,600,[mdc],0,0,SRCCOPY
    pop eax
    invoke DeleteDC,eax
    invoke Sleep,25
    invoke GetAsyncKeyState,VK_RETURN
    test eax,eax
    jz scorescreen
    @@:
    invoke GetAsyncKeyState,VK_RETURN
    test eax,eax
    jnz @b
     
    retn
     
    nullproc:
    xor eax,eax
    ret
    jmp nullproc
     
    .end start ;==================================================================================================================
    ;==================================================================================================================
    ;==================================================================================================================
    ;==================================================================================================================
    ;==================================================================================================================
    ;==================================================================================================================
    ;==================================================================================================================
    ;==================================================================================================================
     
    inttohex dd _inttohex
    _inttohex:
    jmp @f
    scorestr db 'Your stupid score is: 0x'
    holder dd 0,0,0 ;We should need 6 bytes to make it true
    @@:
    xor ebx,ebx
    mov edx,[esp+4] ;This will hold the parametter
    mov eax,edx
    and eax,0ff000000h ;Lets get our first byte
    shr eax,4*6        ;Moving to AL
    call getbits
    cmp al,0ah
    jge @f
    sub al,7
    @@:
    add al,55
    cmp bl,0ah
    jge @f
    sub bl,7
    @@:
    add bl,55
    push 0
    call setbits ;Here we set the results in the result buffer
     
     
     
    mov eax,edx
    and eax,0ff0000h ;Lets get our first byte
    shr eax,4*4        ;Moving to AL
    call getbits
    cmp al,0ah
    jge @f
    sub al,7
    @@:
    add al,55
    cmp bl,0ah
    jge @f
    sub bl,7
    @@:
    add bl,55
    push 2
    call setbits ;Here we set the results in the result buffer
     
     
     
    mov eax,edx
    and eax,0ff00h ;Lets get our first byte
    shr eax,4*2        ;Moving to AL
    call getbits
    cmp al,0ah
    jge @f
    sub al,7
    @@:
    add al,55
    cmp bl,0ah
    jge @f
    sub bl,7
    @@:
    add bl,55
    push 4
    call setbits ;Here we set the results in the result buffer
     
     
     
    mov eax,edx
    and eax,0ffh
    call getbits
    cmp al,0ah
    jge @f
    sub al,7
    @@:
    add al,55
    cmp bl,0ah
    jge @f
    sub bl,7
    @@:
    add bl,55
    push 6
    call setbits
     
     
    lea eax,[holder] ;Set the result
    retn 4 ;Yes, lets free it all =P
    getbits:
    ;This function will separate AL in 2
    mov bl,al ;Duplicate AL to BL
    and al,0fh
    shr bl,4
    retn
     
    setbits:
    lea ecx,[holder]
    add ecx,[esp+4]
    mov byte [ecx],bl
    inc ecx
    mov byte [ecx],al
    retn 4
     
     
    section 'crapz' resource data readable
     
     
     
      directory RT_DIALOG,dialogs,\
                RT_BITMAP,bitmaps
     
      ;resource imag,\
      ;         1,LANG_ENGLISH+SUBLANG_DEFAULT,'apple.bmp'
     
      ;directory RT_DIALOG,dialogs
     
     
     
      resource dialogs,\
               37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration
     
      dialog demonstration,'Snake From HELL',0,0,525,365,WS_VISIBLE
      ;dialogitem 'STATIC','&Caption:',-1,10,10,70,8,WS_VISIBLE
      enddialog
     
    ;directory RT_BITMAP,bitmap
     
    resource bitmaps,\
             10,LANG_ENGLISH+SUBLANG_DEFAULT,apple
     
    bitmap apple,'apple.bmp'
     
     
    section 'DKWKZ4R' readable writeable
     
     
     
    mdc dd ?
    mtext dd ?
    mbmp dd ?
    mapple dd ?
    clblack dd ?
    clgray dd ?
     
    hasapple db ?
    applex dd ?
    appley dd ?
     
    _zstart:
    snakesize dd ?
    snakebody dd ?
    myscore dd ?
    haswalls dd ?
    dead db ?
    ispause db ?
    hasend db ?
    speedx dw ?
    speedy dw ?
    _zend:

:thumbsup::thumbsup:
 
Patulong naman po, paano po ba maglagay ng numerical input sa Assembly language? Kapag al po kasi ginagamit operand types do not match daw. Or kung meron pong marunong mag convert ng ascii input into numerical. Kelangan po kasi para sa looping. Sana po may makatulong!!

:pray::pray::pray:
 
Patulong naman po, paano po ba maglagay ng numerical input sa Assembly language? Kapag al po kasi ginagamit operand types do not match daw. Or kung meron pong marunong mag convert ng ascii input into numerical. Kelangan po kasi para sa looping. Sana po may makatulong!!

:pray::pray::pray:

Assemble with TASM.

Code:
; Jellyx/Relminator
.model small   ; data segment < 64k, code segment < 64k
.stack 200h    ; set up 512 bytes of stack space
.386
; ===========================================================================
.data

;Constants
cr          equ 13                      ;carriage return
lf          equ 10			;line feed
MAXINPUT    equ 5                       ;max char for input

        ;data to hold our input
        Paralist label byte             ;set udt
	maxlen db MAXINPUT              ;input length limiter
	asclen db ?                     ;length of actual string
	kbdata db MAXINPUT dup(?)       ;string data

            ;the prompts
Prompt      db "Type first  number:$"      ;addend
Prompt2     db "Type second number:$"     ;addend
Prompt3     db "     The sum is:$"

binval      dw 0                ;first binary value
binval2     dw 0                ;second bin value
ascsum      db MAXINPUT+1 dup(?) ;answer string

               ;          1         2         3         4         5         6         7
               ;12345678901234567890123456789012345678901234567890123456789012345678901234567890"
mess1       db "Program to add 2 values"
mess2       db "****ADDITION****"
mess3       db "Continue? y/n"


                  ;          1         2         3         4         5         6         7
                  ;12345678901234567890123456789012345678901234567890123456789012345678901234567890"
name1          db " Submitted by... "
name2          db " xxxxxxxxxxxxxx  "
name3          db " xxxxxxxxxxxxxx  "
name4          db " xxxxxxxxxxxxxx  "
name5          db " Press any key..."


topline     db 0dah, 38 dup(0c4h),0bfh
midline     db 0b3h, 38 dup(32),0b3h
botline     db 0c0h, 38 dup(0c4h),0d9h


               ;         1         2         3         4
               ;12345678901234567890123456789012345678901234567890
star        db "* @ $ * @ $ * @ $ * @ $ * @ $ * @ $ * @ $ * @ $ *"
maxstar     db 40

attrib      db 0


.code



;*****************************************************************
;Prints a string on the screen
Print Macro  Message
        pusha
	xor ax,ax
	mov ah, 09h		        ;print interrupt 21, 9
	lea dx, message			;Load Effective Address(offset)
	int 21h				;print it
	popa
EndM Print
;*****************************************************************
CursorOFF Macro
    pusha
    mov ah, 01                           ;disable cursor
    mov cx, 2000h
    int 10h                              ;disable it baby
    popa
EndM CursorOFF
;*****************************************************************
CursorON Macro
    pusha
    mov ah, 01                           ;enable cursor
    mov cx, 0005h
    int 10h                              ;enable it baby
    popa
EndM CursorON
;*****************************************************************
;sets the cursor at row col
Locate Macro row, col
    pusha
    mov ah, 02h				;int 10, 2
    xor bx, bx                          ;bx should be zero
    mov dh, row				;dh=row, dl = column
    mov dl, col
    int 10h				;do it
    popa
EndM Locate

;*****************************************************************
;reads the keyboad buffer
Input Macro
	;needs ax to be unused
	;returns in AH the scancode
	;returns in AL the asciicode
	mov   ah, 10h                   ; check for input
   	int   16h
EndM Input

;*****************************************************************
PrintChar Macro aschar
    pusha
        mov al, aschar
        mov ah, 0ah
        mov bh, 00
        mov cx, 1
        int 10h
    popa
EndM PrintChar

;*****************************************************************
;needs: ES:BP >>> Pointer to string
;cx >> numchars
PrintString  macro row, col,attrib, numchars
    pusha
    mov   ax, 1301h                      ;request display
    mov   bl, attrib                     ;attrib
    mov   bh, 0                          ;page
    mov   dh, row
    mov   dl, col
    mov   cx, numchars
    int   10h
    popa
endm printstring


;*****************************************************************

draw_box Macro
    local x_loop
    pusha
    mov attrib,00110100b
    lea bp, topline
    PrintString  0,0,attrib, 40
    lea bp, midline
    mov cx, 22
    xor ch,ch
x_loop:
    PrintString  cl,0,attrib,40
    loop x_loop
    lea bp, botline
    PrintString  23,0,attrib, 40
    popa
endm draw_box


;*****************************************************************
;note:
;ascval = ascii string of asclen
;asclen = length of string
;binval = binary value to convert
;needs ax(or any free word register) to be equal to asclen
;ie: type "movzx, ax asclen" before calling the macro

bin2asc macro binval, ascval, asclen
        local  L_bin2asc, L_bin2ascend
        pusha                           ;save regs
        mov cx, 0010                    ;division factor
        lea si, ascval - 1              ;align it
        mov dx, asclen                  ;length of string
        add si, dx                      ;start at last byte
        mov ax, binval                  ;set ax to hold our temp val
        ;loop until less than 10
        ;converting from binary to ascii
        ;involves continously dividing the base 2 binary value
        ;with an increasing base 10 value until the
        ;remainder is less than 10. We are technically using the
        ;remainder to convert.
    L_bin2asc:
        cmp ax, cx                      ;ax less than 10?
        jl L_bin2ascend                 ;yep so convert last remainder
        xor dx, dx                      ;clear dx for return
        div cx                          ;ax = quotient
                                        ;dx = remainder(we only need this)
        or dl, 30h                      ;put 3 on the upper nibble
        mov [si], dl                    ;copy to asc string
        dec si                          ;dec pointer to ascval
        jmp L_bin2asc                   ;loop to top until ax<10
    L_bin2ascend:
        or al, 30h                      ;last remainder
        mov [si], al                    ;copy
        popa                            ;restore regs
endm bin2asc

;*****************************************************************
;note:
;ascval = ascii string of asclen
;asclen = length of string
;binval = binary value to convert (dw)
;needs ax(or any free word register) to be equal to asclen
;ie: type "movzx, ax asclen" before calling the macro

asc2bin macro binval, ascval, asclen
        local L_asc2bin
        pusha
        mov cx, asclen                  ;iterator
        lea si, ascval-1                ;align
        mov dx, asclen                  ;length of string
        add si, dx                      ;start from last char
        mov bx, 1                       ;multiplier

        ;now converting from ascii to binary is the reverse of bin2asc
        ;we multiply each char from right to left n an increasing base 10 number
        ;then adding it to the binary value
        ;ie: binval += 10^(len-nthletter)
        L_asc2bin:
        mov al, [si]
        and ax, 000Fh                   ;clear 3 in ascii
        mul bx                          ;dx:ax = product
        add binval, ax                  ;add to value
        mov ax, bx                      ;copy multiplier
        imul ax, 10                     ;multiplier *=10  (^n)
        mov bx, ax                      ;copy back
        dec si                          ;next letter
        dec cx                          ;I could use a loop but I like to
                                        ;mix it up (this BTW is faster on
                                        ;a 486+ cpu)
        jnz L_asc2bin
        popa
endm asc2bin


;*****************************************************************
;this waits for screen retrace/refresh or our demo being in ASM
;would as fast as an x-wing on steroids. :*)

waitretrace proc
        mov dx,03dah            ;0x3da9 vertical retrace port

wret:
        in al,dx
        and al,08h		; is vga in retrace?
jnz wret
wref:
        in al,dx
        and al,08h		;is retrace finished?
jz wref


ret
waitretrace endp

;*****************************************************************

textmode         proc
   mov   ah, 00h                        ;set video mode
   mov   al, 01h                        ;mode 40*25
   int   10h                            ;enter 80x25x16 mode
   ret
textmode         endp

;*****************************************************************
ClearScreen Proc
	pusha				;preserve general regs
	mov ax, 0600h			;int 10, 6(scroll screen)
	mov bh, 0Fh			;color white on Black
	mov cx, 0000			;row0,col0
	mov dx, 1828h			;25,80
	int 10h                         ;scroll(clear it)
	popa				;restore regs
	ret
ClearScreen Endp
;*****************************************************************
;destroys ax, dx
Getinput proc
   pusha
   mov ah, 0ah				;int 20, a (buffered input)
   lea dx, paralist			;load parlist
   int 21h				;do it
   popa
   ret
Getinput Endp

;*****************************************************************

Sumformat proc
   pusha

   mov ax , 0                          ;checker if number
   mov cx, MAXINPUT + 1                ;length
   lea si, ascsum                      ;load sum
  setzero:
   cmp ax, 0                           ;have we processed a num?
   jne notzero                         ;no
   cmp byte ptr[si], 30h               ;zero?
   jne notzero                         ;no so process numeric test
   mov byte ptr[si], 20h               ;yes, change to space
   notzero:                            ;check if numeral
   cmp byte ptr[si], 30h               ;0
   jb less0                           ;<=0 then change to space
   cmp byte ptr[si], 39h               ;>=9?
   jbe isnum                           ;no so loop again
   less0:
   mov byte ptr[si], 20h               ;blank it
   jmp notnum
   isnum:
   mov ax, 1                           ;we have processed a number
   notnum:
   inc si                              ;next byte
   loop setzero                        ;loop until cx < 0
   popa
   ret
Sumformat endp

;*****************************************************************
;*****************************************************************
;*****************************************************************
;*****************************************************************
;*****************************************************************
;*****************************************************************
;Main proggie

start:
    mov   ax, @data			;use the @ operator
    mov   ds, ax                        ;ds now points to the data segment.
    mov   es, ax                        ;es now points to the data segment.
    call  textmode			;set to textmode
    CursorOff

    draw_box


    mov attrib, 01110000b
    lea bp, mess1                       ;Title
    PrintString  1, 6,attrib, 23      ;

    mov attrib, 10001111b
    lea bp, mess2                       ;addition
    PrintString  3, 9,attrib, 16      ;

    locate 7,6                         ;row 1, col 1
    Print Prompt                        ;print promter
    CursorOn                            ;show cursor for inoput
    call Getinput                       ;get input
    movzx ax, asclen                    ;use movzx since ax is word and asclen is byte
    asc2bin binval, kbdata, ax          ;convert kbdata to binary

    locate 9,6                         ;row 1, col 1
    Print Prompt2                       ;next number
    call Getinput                       ;get input for next num
    movzx ax, asclen                    ;ditto
    asc2bin binval2, kbdata, ax         ;convert and put to binval2

    mov ax, binval                      ;copy it to ax
    add ax, binval2                     ;add it

    mov bx, MAXINPUT+1                  ;lennth of ascsum
    bin2asc ax, ascsum, bx              ;convert ascsum to ascii and put it to ax

    CursorOff                           ;hide the cursor
    lea bp, ascsum                      ;es:bp = address of ascsum
    call Sumformat                      ;format it to erase leading zeros
                                        ;and non-numeric data

    locate 12, 6                         ;row 5 column 1
    Print Prompt3                       ;prompt3
    PrintString  12, 23, 10011010b,MAXINPUT+1      ;print sum


    l_again:
    mov attrib, 11001010b
    lea bp, mess3                       ;
    PrintString  22, 13,attrib, 13      ;print "again?"

quit_loop:
    input
    cmp al, 79h                         ;"y"
    je start
    cmp al, 59h                         ;"Y"
    je start
    cmp al, 6eh                          ;"n"
    je end_it
    cmp al, 4eh                          ;"N"
    je end_it
    jmp quit_loop
end_it:
    CursorOff
    call clearScreen

    xor bx, bx

star_loop:
    call waitretrace
    call waitretrace
    call waitretrace
    call waitretrace
    call waitretrace
    call waitretrace
    call waitretrace
    call waitretrace

    mov attrib, 00001111b
    lea bp, star+bx
    PrintString  0, 0, attrib, 40
    lea bp, star + bx
    PrintString  23, 0, attrib, 40
    inc bx
    and bx, 3


    mov attrib, 11001101b
    lea bp, name1
    PrintString  3, 10, attrib, 17
    mov attrib, 11111011b
    lea bp, name2
    PrintString  8, 10, attrib, 17
    mov attrib, 11101001b
    lea bp, name3
    PrintString  10, 10, attrib, 17
    mov attrib, 10101110b
    lea bp, name4
    PrintString  12, 10, attrib, 17
    mov attrib, 10001111b
    lea bp, name5
    PrintString  18, 10, attrib, 17



    mov   ah, 01h                        ;check for keypress
    int   16h
    jz star_loop

    mov   ah, 4ch                       ;return to dos
    mov   al, 00h
    int   21h                           ;return to dos
end start
 
sir pahelp naman eto user must enter a number the print out the size of the inputed number

sample run:
enter number: 5
1
2
3
4
5

i cocount nya po ung number hangang sa ininput nung user.hangang 9 lang po pwede iinput..

help po sir..
 
sir pahelp naman eto user must enter a number the print out the size of the inputed number

sample run:
enter number: 5
1
2
3
4
5

i cocount nya po ung number hangang sa ininput nung user.hangang 9 lang po pwede iinput..

help po sir..

Brad mag increment ka, tapos kada increment ng number ipprint nya yung number. basta yung AH laging 0 para hindi hex ang maprint kundi whole number. ayan ah may logic ka na. Wag lang puro spoonfeed. Lahat tayo pinag aaral. Wag mo sana mamasamain yung sinabi ko. Study hard dre.
 
Introduction to Machine Language

DEBUG

A software that is classifies as debugger which is used for testing and debugging executable programs
Advantages
It is Free
It is universally available
It is simple to use
It requires relatively little memory

DEBUG COMMANDS

E (Enter)
-enable you to key in data or machine instruction into memory beginning at a specific location address.
E.g -E 0200

D (Display or Dump)
Displays the contents of a portion memory ni hex and ASCII forms starting with the given address
E.g. -D 0200

A (Assemble)
Allows you to create a program in mnemonic or symbolic code.
E.g. -A 0100

T (Trace)
Runs he program in single-step mode. It also displays the new values of the registers and the next instruction to be executed.
E.g -T

G (Go)
Runs the program as a whole in memory an displays the output
E.g. -G

U (Unassemble)
Lists all the instructions contained in the program beginning at the given address. You can also specify the last address location.
E.g. -U 0100
-U 0100 0109

N (Name)
Gives a name to your program, coded as N <path> <filename>
Extention nae is .COM
E.g. -N A:SAMPLE.COM

W (Write)
Saves the program onto disk storage
E.g. -W

BASIC ASSEMBLY INSTRUCTIONS USED IN DEBUG

MOV (Move Data)
Copies and transfers data between two registers, or between an immediate data to a register
Format: MOV <register>, <register>
MOV <register>, <immediate data>
Example: MOV AX, BX
MOV CX, 5083
MOV CL, DL
MOV BL, 33

ADD (Add Data)
Used to get the sum of two registers or a register and an immediate data, and stores the result to the left most register
Format: ADD <register>, <register>
ADD <register>, <immediate data>
Example: ADD CX, BX
ADD AX, 0308
ADD AL, BL
ADD DH, 85

MUL (Multiply Data)
It is used to get the product of a given register and AX register, and stores the result to AX register. If the product is greater than 16 bits, the overflow is stored in DX register.
Format: MUL <register>
Example: MUL CX

DIV (Divide Data)
Used to divide the value of a given register and AX register, stores the quotient to AX and the remainder to DX registers respectively
Format: DIV <register>
Example DIV BX

INC (Increment by One)
Used to increase the value of the register by one (1).
Format: INC register
Example: INC AX
INC CH

DEC (Decrement by One)
Opposite of INC, decreases the value of the register by one (1).
Format: DEC <register>
Example: DEC AX
DEC CH

LOOP (Loop Until Complete)

It controls the execution of a program segment in a specified number of times.
The CX register should contain a count value before starting the loop and automatically decrements by one (1)
If CX is not equal to zero (0), it transfers to its operand address which points to the start of the loop; otherwise it drops to the nest instruction.
Format: LOOP <offset address>
Example: LOOP 0108


CODING ASSEMBLY LANGUAGE IN TASM

Comment

Ignored by the assembler.
Can improve program’s readability and clarity
Begins with a semicolon (;)
Ways to include comment
Any statement whose first non-block character is a semicolon
Example:
; This program displays Hello, World!
At the end of an instruction
Example:
MOV AX, 8053H ;initializes the value of AX to 8053

Reserved Words

Words in which the assembler assigns a special meaning and it cannot be used as identifiers
Using reserved words for a wrong purpose causes the assembler to generate an error message

Categories of reserved words

Instructions
Statements that will be translated into machine language and executed by the computer.
Examples:
MOV ADD SUB
MUL DIV INC
DEC LOOP CMP


Directives
Statements that give information to the assembler
Sometimes called pseudo-ops
Examples:
TITLE DOSSEG .MODEL
.STACK .DATA .CODE

Rules in Constructing Valid identifier

It must use letters (A...Z, a…z), number (0…9) and/or special characters like underscore (_), question mark (?) and at sign (@).
It must always start with a letter
It must not use reserved words
It must not exceed to 31 character.
Examples of valid identifiers:
neym r2d2
num_1 msg8
Examples of invalid identifiers:
title num-1
4ever

Statement
May begin anywhere on the line
Each line can only contain one statement
Assembly is not case sensitive
Examples:
ADD AX, BX ; uses 2 operands
DEC CX ; uses
RET ; no operand

Most common directives

TITLE

It creates a title (up to 60 characters) of a source listing.
Format:
TITLE <TEXT>
Examples:
TITLE This program displays Kumusta, BUPC!
TITLE PROGRAM1.ASM

.MODEL

It specifies and initializes the memory model before defining any segment
Format:
.MODEL <memory-model>
Examples:
.MODEL TINY
.MODEL SMALL
.MODEL MEDIUM

.STACK

It defines the size of the attack. The default stack size is 1,024 bytes which you can overrule.
Format:
.STACK <size>
Example:
.STACK 0100h

.DATA

It defines and marks the beginning of data segment
Format:
.DATA
Example:
.DATA

.CODE

It defines and marks the code segment which consists of a set of instructions.
Format:
.CODE
Example:
.CODE

START:

Defines the start of program execution
Format:
START:
Examples:
START:

END

It is placed at the last line of the source code
Format:
END
Example:
END START

STRING

Used for descriptive data such as person’s name or simply a message.
It must end with dollar ($) symbol and defined in double quotation marks (“ “).
DB is the conventional format for defining string of any length.
Example:
neym db “Louis Vuitton$”

Numeric Constant

Used to define arithmetic values and memory address.
It is defined with a radix specifier such as d for decimal, b for binary and h for hexadecimal.
Example:
msg db “Bon jour, monsieur!”, 0Ah, 0Dh, “$”
msg db “Bon jour, monsieur!”, 10d, 13d, “$”
msg db “Bon jour, monsieur!”, 00001010b, 00001101b, “$”

Screen Processing

The monitor
A typical video screen has 80 columns numbered form 0 to 79 and 25 rows numbered from 0 to 24.

Clearing the screen in Assembly Approach

Interrupt 10h and function 06h handles the process of clearing the screen and scrolling
Clear all or part of display beginning at any screen location and ending at any higher-numbered location.

Sample code shows how to clear screen code in assembly

MOV AX, 0600h ; AH = 00h (scroll), AL, 00h (Full screen)
MOV BH, 07h ; 0 (BLACK BACKGROUND), 7 (WHITE TEXT COLOR)
MOV CX, 0000h ; CH = 00H (ROW), CL, 00H (COLUMN)
MOV DX, 184Fh ; DH = 18H (ROW), DL=4FH (COLUMN)
INT 10h ; CALL INTERRUPT SERVICE

SETTING THE CURSOR FUNCTION


Interrupt 10h is the BIOS operation for screen handling and function 02h tells the operation to set the cursor
Its position determines where the next character is to be displayed.

MOV AH, 02H ; REQUEST TO SET THE CURSOR POSITION
MOV BH, 00H ; PAGE NUMBER 0
MOV DH, 0AH ; ROW - 10 IN DECIMAL
MOV DL, 08H ; COLUMN = 8 IN DECIMAL
INT 10H

MAY CONTINUATION PA PO ITO, WAIT NYO LANG

Press thanks kung nakatulong,

Accepting Requests for Tutorial in any Programming Languages

Maraming Thanks dito... :thumbsup: makakatulong ito para sa review ko sa exam... :reading:

:more:
 
Back
Top Bottom