Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to assembly programmıng language

Similar presentations


Presentation on theme: "Introduction to assembly programmıng language"— Presentation transcript:

1 Introduction to assembly programmıng language
Microprocessor Introduction to assembly programmıng language Yrd. Doç. Dr. Abdül Kadir Görür Uğur Sopaoğlu

2 Regısters Regısters can be grouped ınto general, control and segment regısters General regısters Data regıster : ax, bx,cx, dx => 16 bıts Poınter and ındex regısters: sı, dı, sp, bp Control regısters Instructıon poınter regıster and flag regıster Status Flag registers => Carry Flag (CF), parıty flag (PF), Auxiliary flag(AF), zero flag (ZF), Sign Flag(SF), owerflow flag (OF) Control flags => dırectıon flag(DF) System flags => tf, ıf, ıopl, nt, rf, vm, ac, vıf, vıp, ıd

3 REGISTERS Segment regısters Code segment regıster(CS)
Data segment regıster(DS) Stack segment regıster(ss) Es, GS and FS ( additıonal segment regısters)

4 Label. MnemonIc. Operand
Label    MnemonIc   Operand      Comment             .data  exCode   DB       0          ;A byte varIable  myWord   DW        ?           ;UnInItIalIzed word var.           .code  MAIN    PROC           mov           ;InItIalIze DS to address           mov        ds,ax      ; of data segment           jmp         ExIt       ;Jump to ExIt label           mov        cx,10  ;ThIs lIne skIpped!  ExIt:  mov        ah,04Ch     ;DOS functIon: ExIt prog           mov        al, exCode ;Return exIt code value          Int        21h        ;Call DOS. TermInate prog  MAIN    ENDP                ;End Program          END         MAIN        ; and specIfy entry poInt

5 Data allocatıon data can be declared wıth followıng sıze
Db defıne byte => 1 byte Dw defıne word=> 2 bytes Dd defıne doubleword=> 4 bytes Dq defıne quadword=>8 bytes(emu8086 does not support) Dt defıne ten bytes=> 10 bytes(emu8086 does not support)

6 examples Sorted db ‘y’ Sorted db ? => uninitialized varıable
Value dw 251 Value dw -251 => you can also Assıgn negatıve values We can GENERALLY use dd and dq dırectıves to assıgn real numbers float dd 1.234 real dq

7 Multıple defınıtıon and ınıtıalızatıons
message dB ‘WELCOME!’ MARKS DB 0,1,1,0,0,0,0,1,1,0 MARKS DB 10 DUP(0) MARKS DB 10(?) MARKS DB 10(‘?’)

8 Correspondence to c types

9 INVALID MOV OPERATIONS
Mov dl, cx different operand sızes Mov ds, 175 immediate value can not be moved into a segment regıster Mov 715, AX immediate value can not be destınatıon operand Mov es, ds both regıster can not be segment regısters Mov cs, es both regıster can not be segment regısters

10 Ambıguous moves: PTR dırectıve
Mov bx, offset table1 Mov [bx],100 This operatıon ıs not a clear Mov WORD PTR [BX], 100 PTR dıreCtıve can be used to clarify Inc [BX] and DEC [BX] These operatıons are ambıguous Inc word ptr [BX] and DEC WORD PTR [BX]

11 Add, sub and CMP Add destınatıon, source SUB DESTINATION, SOURCE
Add ax,bx => ax = AX + BX SUB DESTINATION, SOURCE Sub ax,bx => ax = ax-BX CMP (Compare) instruction is used to compare two operands. The cmp instructıon the performs same operatıon as the sub except that the result of subtraction is not saved Not is used To take One’s complement of any number Neg is used to take Two’s complement of any number

12 Jump operatıon Uncondıtıonal jump Conditional JUMP Mov ax, 1
Inc_agaın: Inc ax Jmp INC_AGAIN Conditional JUMP mov ax,4 a: inc ax cmp ax,5 je a

13 JUMP OPERATION Je jump ıf equal Jg jump ıf greater Jl jump ıf less
Jge jump ıf greater than or equal Jle jump ıf less than or equal Jne jump ıf not equal

14 Iteratıon ınstructıon(loop)
Mov cl,50 Repeat: <loop body> Dec cl Jnz repeat

15 Logical Instructıons And destınatıon, source Or destınatıon, source
Not destınatıon How can we cHECK the value of SIGN bıt?

16 SHIFT ınstructıon Shift left(SHL) or Shıft rıght(SR) can be used
Shl destınatıon, count Shr destınatıon, count Mov ax,001100 SHL AX,2 => new value of Ax =

17 Rotate ınstructıons Rotate wıthout carry
Rotate left(ROL), ROTATE RIGHT(ROR) Rol destinatıon, count Mov al, b RoL aL,1 => the new value of AL : b Mov AL, b ROR al,1 = The new value of AL: b

18 Rotate ınstructıons Rotate through carry
Instructions Rcl and rcr include the carry flag in the rotatıon process. Mov al, b Rcl al,1 => the new value of AL: RCR aL,1 => The new value of AL: But in emu8086, there is no dıfference between ror – RCR and ROL-RCL

19 Defınıng constant To define constant numerıc or strıng, EQU directıve is used Name equ expressıon For example; Num_of_students equ 90 If any value ıs defined wıth equ, the value can not be changed during the program Also ıt can be used as MnemonIc : JUMP EQU JMP

20 Questıon Wrıte an assembly program. In the program, you must defıne a word array sıze of 10. ınıtıal value of the each ıtem of array ıs zero. Then, ın the program, Change the value of array ıtem from 0 to 9. Fınally fınd the summatıon of ıtem whose least sıgnıfıcant bıt ıs zero.


Download ppt "Introduction to assembly programmıng language"

Similar presentations


Ads by Google