Beşiktaş Forum  ( 1903 - 2013 ) Taraftarın Sesi


Geri git   Beşiktaş Forum ( 1903 - 2013 ) Taraftarın Sesi > Eğitim Öğretim > Dersler - Ödevler - Tezler - Konular > Elektronik & Bilgisayar

 
 
LinkBack Seçenekler Stil
Alt 06-09-2008, 15:13   #10
ยŦยк
 
Constantin - ait Kullanıcı Resmi (Avatar)
 

One of the facilities that the use of macros offers is the creation of libraries, which are groups of macros which can be included in a program from a different file.

The creation of these libraries is very simple, we only have to write a file with all the macros which will be needed and save it as a text file.

To call these macros it is only necessary to use the following instruction Include NameOfTheFile, on the part of our program where we would normally write the macros, this is, at the beginning of our program, before the declaration of the memory model.

The macros file was saved with the name of MACROS.TXT, the instruction Include would be used the following way:
;Beginning of the program
Include MACROS.TXT
.MODEL SMALL
.DATA
;The data goes here
.CODE
Beginning:
;The code of the program is inserted here
.STACK
;The stack is defined
End beginning
;Our program ends
________________________________________

Program Examples
In this section we provide you several assembler programs to run in the debug program. You can execute each assembler program using the "t" (trace) command, to see what each instruction does.
Also you will find some examples using Assembler Program (TASM)

• Debug Program Examples
o Example 1
o Example 2
o Example 3
o Example 4
o Example 5
o Example 6
o Example 7
o Example 8
o Example 9
o Example 10
o Example 11

• Assembler Program Examples
o Example 1
o Example 2
o Example 3
o Example 4
o Example 5
o Example 6
________________________________________
Debug Program Examples
First example
The only thing that this program does is to save two values in two registers and add the value of one to the other.
-a0100
297D:0100 MOV AX,0006 ; Puts value 0006 at register AX
297D:0103 MOV BX,0004 ;Puts value 0004 at register BX
297D:0106 ADD AX,BX ;Adds BX to AX contents
297D:0108 INT 20 ;Causes end of the Program
Second example
This program displays on the screen 15 times a character string.
- a100
0C1B:0100 jmp 125 ; Jumps to direction 125H
0C1B:0102 [Enter]
- e 102 'Hello, How are you ?' 0d 0a '$'
- a125
0C1B:0125 MOV DX,0102 ; Copies string to DX register
0C1B:0128 MOV CX,000F ; Times the string will be displayed
0C1B:012B MOV AH,09 ; Copies 09 value to AH register
0C1B:012D INT 21 ; Displays string
0C1B:012F DEC CX ; Reduces in 1 CX
0C1B:0130 JCXZ 0134 ; If CX is equal to 0 jumps to 0134
0C1B:0132 JMP 012D ; Jumps to direction 012D
0C1B:0134 INT 20 ; Ends the program
Third example
This program is good for changing the form of the cursor.
-a100
297D:0100 MOV AH,01 ;Function to change the cursor
297D:0102 MOV CX,0007 ;Forms the cursor
297D:0105 INT 10 ;Calls for BIOS
297D:0107 INT 20 ;Ends the program
Fourth example
This program uses DOS 21H interruption. It uses two functions of the same: the first one reads the keyboard (function 1) and the second one writes on the screen. It reads the keyboard characters until it finds a carriage return.
-a100
297D:0100 MOV AH,01 ; Funtion 1 (reads keyboard)
297D:0102 INT 21 ; Calls for DOS
297D:0104 CMP AL,0D ; Compares if what is read is a carriage return
297D:0106 JNZ 0100 ; If it is not, reads another character
297D:0108 MOV AH,02 ; Funtion 2 (writes on the screen)
297D:010A MOV DL,AL ; Character to write on AL
297D:010C INT 21 ; Calls for DOS
297D:010E INT 20 ; Ends the program
Fifth example
This program displays on the screen a binary number through a conditional cycle (LOOP) using byte rotation.
-a100
297D:0100 MOV AH,02 ; Function 2 (writes on the screen)
297D:0102 MOV CX,0008 ; Puts value 0008 on register CX
297D:0105 MOV DL,00 ; Puts value 00 on register DL
297D:0107 RCL BL,1 ; Rotates the byte in BL to the left by one bit through the ;carry flag
297D:0109 ADC DL,30 ; Converts flag register to1
297D:010C INT 21 ; Calls for DOS
297D:010E LOOP 0105 ; Jumps if CX > 0 to direction 0105
297D:0110 INT 20 ; Ends the program
Sixth example
This program prints a zero value on hex digits
-a100
297D:0100 MOV AH,02 ; Function 2 (writes on the screen)
297D:0102 MOV DL,BL ; Puts BL's value on DL
297D:0104 ADD DL,30 ; Adds value 30 to DL
297D:0107 CMP DL,3A ; Compares 3A value with DL's contents without affecting
; its value only modifying the state of the car
297D:010A JL 010F ; jumps if
297D:010C ADD DL,07 ; Adds 07 value on DL
297D:010F INT 21 ; Calls for Dos
297D:0111 INT 20 ; Ends the Program
Seventh example
This program is used to print two digit hex numbers.
-a100
297D:0100 MOV AH,02 ; Function 2 (writes on the screen)
297D:0102 MOV DL,BL ; Puts BL value on DL
297D:0104 AND DL,0F ; Carries ANDing numbers bit by bit
297D:0107 ADD DL,30 ; Adds 30 to Dl
297D:010A CMP DL,3A ; Compares Dl with 3A
297D:010D JL 0112 ; Jumps if <0112 direction
297D:010F ADD DL, 07 ; Adds 07 to DL
297D:0112 INT 21 ; Calls for Dos
297D:0114 INT 20 ;Ends the program
Eight example
This program works for printing the first of two digit hex numbers
-a100
297D:0100 MOV AH,02 ; Function 2 (writes on the screen)
297D:0102 MOV DL,BL ; Puts BL value on DL
297D:0104 MOV CL,04 ; Puts 04 value on CL
297D:0106 SHR DL,CL ; Moves per four bits of your number to the rightmost ;nibble
297D:0108 ADD DL,30 ; Adds 30 to DL
297D:010B CMP DL,3A ; Compares Dl with 3A
297D:010E JL 0113 ; Jumps if <0113 direction
297D:0110 ADD DL,07 ; Adds 07 to DL
297D:0113 INT 21 ; Calls for Dos
297D:0115 INT 20 ; Ends the program
Ninth example
This program works for printing the second of two digit hex numbers
-a100
297D:0100 MOV AH,02 ; Function 2 (writes on the screen)
297D:0102 MOV DL,BL ; Puts BL value on DL
297D:0104 MOV CL,04 ; Puts 04 value on CL
297D:0106 SHR DL,CL ; Moves per four bits of your number to the rightmost ;nibble
297D:0108 ADD DL,30 ; Adds 30 to DL
297D:010B CMP DL,3A ; Compares Dl with 3A
297D:010E JL 0113 ; Jumps if <0113 direction
297D:0110 ADD DL,07 ; Adds 07 to DL
297D:0113 INT 21 ; Calls for Dos
297D:0115 MOV DL,BL ; Puts Bl value on DL
297D:0117 AND DL,0F ; Carries ANDing numbers bit by bit
297D:011A ADD DL,30 ; Adds 30 to DL
297D:011D CMP DL,3A ; Compares Dl with 3A
297D:0120 JL 0125 ; Jumps if <125 direction
297D:0122 ADD DL,07 ; Adds 07 to DL
297D:0125 INT 21 ; Calls for Dos
297D:0127 INT 20 ; Ends the Program
Tenth example
This program can read two digit hex numbers
-a100
297D:0100 MOV AH,01 ; Function 1 (reads keyboard)
297D:0102 INT 21 ; Calls for Dos
297D:0104 MOV DL,AL ; Puts Al value on DL
297D:0106 SUB DL,30 ; Subtracts 30 from DL
297D:0109 CMP DL,09 ; Compares DL with 09
297D:010C JLE 0111; Jumps if <= 0111 direction
297D:010E SUB DL,07 ; Subtracts 07 from DL
297D:0111 MOV CL,04 ; Puts 04 value on CL register
297D:0113 SHL DL,CL ; It inserts zeros to the right
297D:0115 INT 21 ; Calls for Dos
297D:0117 SUB AL,30 ; Subtracts 30 from AL
297D:0119 CMP AL,09 ; Compares AL with 09
297D:011B JLE 011F ; Jumps if <= 011f direction
297D:011D SUB AL,07 ; Subtracts 07 from AL
297D:011F ADD DL,AL ; Adds Al to DL
297D:0121 INT 20 ; Ends the Program
Eleventh example
This program keeps reading characters until it receives one that can be converted to a hex number
-a100
297D:0100 CALL 0200 ; Calls for a procedure
297D:0103 INT 20 ;Ends the program
-a200
297D:0200 PUSH DX ; Puts DX value on the stack
297D:0201 MOV AH,08 ; Function 8
297D:0203 INT 21 ; Calls for Dos
297D:0205 CMP AL,30 ; Compares AL with 30
297D:0207 JB 0203 ; Jumps if CF is activated towards 0203 direction
297D:0209 CMP AL,46 ; Compares AL with 46
297D:020B JA 0203 ; jumps if 0203 direction
297D:020D CMP AL,39 ; Compares AL with 39
297D:020F JA 021B ; Jumps if 021B direction
297D:0211 MOV AH,02 ; Function 2 (writes on the screen)
297D:0213 MOV DL,AL ; Puts Al value on DL
297D:0215 INT 21 ; Calls for Dos
297D:0217 SUB AL,30 ; Subtracts 30 from AL
297D:0219 POP DX ; Takes DX value out of the stack
297D:021A RET ; Returns control to the main program
297D:021B CMP AL,41 ; Compares AL with 41
297D:021D JB 0203 ; Jumps if CF is activated towards 0203 direction
297D:021F MOV AH,02 ; Function 2 (writes on the screen)
297D:022 MOV DL,AL ; Puts AL value on DL
297D:0223 INT 21 ; Calls for Dos
297D:0225 SUB AL,37 ; Subtracts 37 from AL
297D:0227 POP DX ; Takes DX value out of the stack
297D:0228 RET ; Returns control to the main program aysegul
09-22-2006, 12:20 AM

Assembler programs Examples( using TASM program)
Example 1
This program reads two characters from the keyboard and prints them on the screen.
;name of the program: one.asm
;
.model small
.stack
.code
mov AH,1h ;Selects the 1 DOS. function
Int 21h ;reads character and return ASCII code to register AL
mov DL,AL ;moves the ASCII code to register DL
sub DL,30h ;makes the operation minus 30h to convert 0-9 digit number
cmp DL,9h ;compares if digit number it was between 0-9
jle digit1 ;If it true gets the first number digit (4 bits long)
sub DL,7h ;If it false, makes operation minus 7h to convert letter A-F
digit1:
mov CL,4h ;prepares to multiply by 16
shl DL,CL ; multiplies to convert into four bits upper
int 21h ;gets the next character
sub AL,30h ;repeats the conversion operation
cmp AL,9h ;compares the value 9h with the content of register AL
jle digit2 ;If true, gets the second digit number
sub AL,7h ;If no, makes the minus operation 7h
digit2:
add DL,AL ;adds the second number digit
mov AH,4CH
Int 21h ;21h interruption
End ;finishes the program code
Example 2
This program prints the a character through j character on the screen
;name the program: two.asm
.model small
.stack
.code
PRINT_A_J PROC
MOV DL,'A' ;moves the A character to register DL
MOV CX,10 ;moves the decimal value 10 to register cx
;This number value its the time to print out after the A ;character
PRINT_LOOP:
CALL WRITE_CHAR ;Prints A character out
INC DL ;Increases the value of register DL
LOOP PRINT_LOOP ;Loop to print out ten characters
MOV AH,4Ch ;4Ch function of the 21h interruption
INT 21h ;21h interruption
PRINT_A_J ENDP ;Finishes the procedure

WRITE_CHAR PROC
MOV AH,2h ;2h function of the 21 interruption
INT 21h ;Prints character out from the register DL
RET ;Returns the control to procedure called
WRITE_CHAR ENDP ;Finishes the procedure
END PRINT_A_J ;Finishes the program code
Example 3
This program prints a predefined value on the screen
;name of the program: three.asm
.model small
.STACK
.code

TEST_WRITE_HEX PROC
MOV DL,3Fh ;moves the value 3Fh to the register DL
CALL WRITE_HEX ;Calls the procedure
MOV AH,4CH ;4Ch function
INT 21h ;Returns the control to operating system
TEST_WRITE_HEX ENDP ;Finishes the procedure

PUBLIC WRITE_HEX
;................................................. .......;
; This procedure converts into hexadecimal number the byte
; is in the register DL and show the digit number;
; Use:WRITE_HEX_DIGIT ;
;................................................. .......;

WRITE_HEX PROC
PUSH CX ;pushes the value of the register CX to the stack memory
PUSH DX ;pushes the value of the register DX to the stack memory
MOV DH,DL ;moves the value of the register DL to register DH
MOV CX,4 ;moves the value numeric 4 to register CX
SHR DL,CL
CALL WRITE_HEX_DIGIT ;shows on the computer screen, the first
;hexadecimal number
MOV DL,DH ;moves the value of the register DH to the register DL
AND DL,0Fh ;ANDing the upper bit
CALL WRITE_HEX_DIGIT ; shows on the computer screen, the second
;hexadecimal number
POP DX ;pops the value of the register DX to register DX
POP CX ; pops the value of the register DX to register DX
RET ;Returns the control of the procedure called
WRITE_HEX ENDP

PUBLIC WRITE_HEX_DIGIT
;................................................. ...............;
; This procedure converts the lower 4 bits of the register
; DL into hexadecimal
; number and show them in the computer screen ;
; Use: WRITE_CHAR ;
;................................................. ...............;

WRITE_HEX_DIGIT PROC
PUSH DX ;Pushes the value of the register DX in the stack memory
CMP DL,10 ;compares if the bit number is minus than number ten
JAE HEX_LETTER ;No , jumps HEX_LETER
ADD DL,"0" ;yes, it converts into digit number
JMP Short WRITE_DIGIT ;writes the character
HEX_LETTER:
ADD DL,"A"-10 ;converts a character into hexadecimal number
WRITE_DIGIT:
CALL WRITE_CHAR ;shows the character in the computer screen
POP DX ;Returns the initial value of the register DX to register DL
RET ;Returns the control of the procedure called
WRITE_HEX_DIGIT ENDP
Constantin Ofline   Alıntı ile Cevapla
 

Bu konuyu arkadaşlarınızla paylaşın


Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir)
 

Yetkileriniz
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Açık
Smileler Açık
[IMG] Kodları Açık
HTML-KodlarıKapalı
Trackbacks are Açık
Pingbacks are Açık
Refbacks are Açık




Türkiye`de Saat: 13:24 .

Powered by vBulletin® Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2

Sitemiz CSS Standartlarına uygundur. Sitemiz XHTML Standartlarına uygundur

Oracle DBA | Kadife | Oracle Danışmanlık



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580