Gazi Üniversitesi Bilgisayar Mühendislii Bölümü



Similar documents
Complete 8086 instruction set

How To Use A Computer With A Screen On It (For A Powerbook)

Computer Organization and Assembly Language

x64 Cheat Sheet Fall 2015

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

The 80x86 Instruction Set

Faculty of Engineering Student Number:

Unpacked BCD Arithmetic. BCD (ASCII) Arithmetic. Where and Why is BCD used? From the SQL Server Manual. Packed BCD, ASCII, Unpacked BCD

8085 INSTRUCTION SET

A Tiny Guide to Programming in 32-bit x86 Assembly Language

8. MACROS, Modules, and Mouse

ASCII and BCD Arithmetic. Chapter 11 S. Dandamudi

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

The x86 PC: Assembly Language, Design, and Interfacing 5 th Edition

King Fahd University of Petroleum and Minerals. College of Computer Science and Engineering. Computer Engineering Department COE 205

Analysis of Win32.Scream

Systems Design & Programming Data Movement Instructions. Intel Assembly

CS 16: Assembly Language Programming for the IBM PC and Compatibles

Assembly Language Tutorial

Character Translation Methods

Writing an 8086 emulator in Python

Machine-Level Programming II: Arithmetic & Control

Z80 Instruction Set. Z80 Assembly Language

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

MS-DOS, PC-BIOS, and File I/O Chapter 13

TIn 1: Lecture 3: Lernziele. Lecture 3 The Belly of the Architect. Basic internal components of the Pointers and data storage in memory

PART B QUESTIONS AND ANSWERS UNIT I

Overview of IA-32 assembly programming. Lars Ailo Bongo University of Tromsø

Computer Organization and Architecture

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Instruction Set. Microcontroller Instruction Set. Instructions that Affect Flag Settings (1) The Instruction Set and Addressing Modes

Outline. Lecture 3. Basics. Logical vs. physical memory physical memory. x86 byte ordering

Using Debug 1 INTRODUCING DEBUG

Instruction Set Architecture

Victims Compensation Claim Status of All Pending Claims and Claims Decided Within the Last Three Years

Software Fingerprinting for Automated Malicious Code Analysis

Appendix C: Keyboard Scan Codes

CS61: Systems Programing and Machine Organization

8051 hardware summary

MICROPROCESSOR BCA IV Sem MULTIPLE CHOICE QUESTIONS

Flash Microcontroller. Architectural Overview. Features. Block Diagram. Figure 1. Block Diagram of the AT89C core

INTRODUCTION TO PROGRAMMING THE 8086

Writing a Simple Operating System from Scratch

MACHINE ARCHITECTURE & LANGUAGE

Machine Programming II: Instruc8ons

LABORATORY MANUAL EE0310 MICROPROCESSOR & MICROCONTROLLER LAB

ELEG3924 Microprocessor Ch.7 Programming In C

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

8086 Microprocessor (cont..)

IA-32 Intel Architecture Software Developer s Manual

by Kip Irvine. Last update: 12/11/2003

X86-64 Architecture Guide

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

64-Bit NASM Notes. Invoking 64-Bit NASM

Abysssec Research. 1) Advisory information. 2) Vulnerable version

HC12 Assembly Language Programming

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

INTRODUCTION TO MALWARE & MALWARE ANALYSIS

MICROPROCESSOR AND MICROCOMPUTER BASICS

Flash Microcontroller. Memory Organization. Memory Organization

Embedded x86 Programming: Protected Mode

8085 MICROPROCESSOR PROGRAMS

esrever gnireenigne tfosorcim seiranib

Hydra. Advanced x86 polymorphic engine. Incorporates existing techniques and introduces new ones in one package. All but one feature OS-independent

PCI BIOS SPECIFICATION. Revision 2.1

Mouse Programming Mouse Interrupts Useful Mouse functions Mouselib.h Mouselib.c

CHAPTER 6 TASK MANAGEMENT

Hardware and Software Requirements

REpsych. : psycholigical warfare in reverse engineering. def con 2015 // domas

Attacks on Virtual Machine Emulators

Instruction Set Architecture

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Abysssec Research. 1) Advisory information. 2) Vulnerable version

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

THUMB Instruction Set

T.C. Yeditepe University. Department of Electrical-Electronics Engineering

1. General function and functionality of the malware

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

TitanMist: Your First Step to Reversing Nirvana TitanMist. mist.reversinglabs.com

Atmel 8051 Microcontrollers Hardware Manual

Using Heap Allocation in Intel Assembly Language

M6800. Assembly Language Programming

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

TOSHIBA CMOS DIGITAL INTEGRATED CIRCUIT SILICON MONOLITHIC T6963C

Return-oriented programming without returns

Self Protection Techniques in Malware

Programmer s Model = model of µc useful to view hardware during execution of software instructions

Manpower Codes Lookup

Future Trends in Airline Pricing, Yield. March 13, 2013

AN108 IMPLEMENTING A REALTIME CLOCK. Relevant Devices. Introduction. Key Points. Overview

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Where we are CS 4120 Introduction to Compilers Abstract Assembly Instruction selection mov e1 , e2 jmp e cmp e1 , e2 [jne je jgt ] l push e1 call e

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

DATING YOUR GUILD

SD Specifications Part A2 SD Host Controller Simplified Specification

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

1 Classical Universal Computer 3

Transcription:

!"!"!#$ %%% % % %% % % & ' ( )$)!"!#*!"!!'!"+!#*!"+!!'!",!#'!"-!#'!".!#' / ' / / /) ' / ((' / (((' /.) ) '/ '( 1)23 4'/ ) 5'(6"+-+73."3#',""#& 8 & ' 6' 6'!"!!!"!# )$) / ' ( 1)' 619 ' 5 9 ' $$)2. 4'/ ) 5 '"+-"7-"!+.',"",& ':) $ ' & ':) < $ '!"=!#( /<< $ < $ > '? '( 1)2. 4'/ ) 5 ',"",& 1

#$# # %&#& ' ='='<='?='6('?('/'6/ ( %&#& ' (/'@>AB(6BAC>A( # #& '& <6'?6'B6'66 ) * # ='='<='?='5'>'>'5'<5'<>'?5'?>'?('6('/'6/& #?6'B6'66'<62 ) )$ 4& +, + D=E'D=F6(F3E' '& + +,-.,G',.'-@'+"""++"+'& $/&* H $& $& H )%%& 1 H % %%2 4& 23 $ 4 ORG 1h MOV AL, var1 MOV BX, var2 program durur VAR1 DB 7 var2 DW 1234h ( a DB 48h, 65h, 6Ch, 6Ch, 6Fh, h b DB 'Hello', 2

MOV AL, a[3] MOV S, 3 MOV AL, a[s] ) 5,.67 )2 4 c DB 5 DUP(9) c DB 9, 9, 9, 9, 9 d DB 5 DUP(1, 2) d DB 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 23 8J1 K k EQU 5 MOV AX, k MOV AX, 5 $/$ <H<@ LHL @ 6 H6@ H 19 @ /H/@ HM@ ( ( $@?? )@ 9 & /N 65'//'>B'>?6'>?6'>?6'>?68 '66'66'668 ' O6' O6' O68 '( 6'( 6' ( 68 'N 6'N 6'N 68 '=<5 '>5@'65@'=>'('N & &??'( <'?<'6N '?B<'6'< /' N >'( N >P?(O'(?(O'<8 '<8?'?'?6''?' '6'?'A'=A'B6' ' B'65 >'65 A'6>'6A'A>'A<>'A<A'AA'6<6'< /6 )# & : /':':B':':B':<':B':L':':B':>':>B': <': B': L': <': B': L': ': 6':/':/' :':/':/B':6':<=L'>/'<>>'( '(5 >' / 3

#$# ) & $ %6<(( $& <?%Q% % $ %5 > & if low nibble of AL > 9 or AF = 1 then AL = AL + 6 AH = AH + 1 AF = 1 CF = 1 AF = CF = P >C%1%%& MOV AX, 15 AH =, AL = Fh AAA AH = 1, AL = 5 < L 6 / R R R R %6<(( $& P<? Q%& AL = (AH * 1) + AL AH = MOV AX, 15h AH = 1, AL = 5 AAD AH =, AL = Fh (15) < L 6 / R R R 4

: 'AB AB ' S$ %6<(( $& P<? Q$ ) & AH = AL / 1 AL = remainder MOV AL, 15 AL = Fh AAM AH = 1, AL = 5 < L 6 / R R R S% %6<(( $& <?%Q% % Q% %5 > & if low nibble of AL > 9 or AF = 1 then AL = AL - 6 AH = AH - 1 AF = 1 CF = 1 AF = CF = P >C%1%%& MOV AX, 2FFh AH = 2, AL = FFh AAS AH = 1, AL = 9 < L 6 / R R R R $ $& operand1 = operand1 + operand2 MOV AL, 5 AL = 5 ADD AL, -3 AL = 2 < L 6 / 5

: :$4 'AB AB ' $). P$ % %%% %OB $ )$ &? 1 AND 1 = 1 1 AND = AND 1 = AND = MOV AL, 'a' AL = 111b AND AL, 1111111b AL = 11b ('A') < L 6 / " " $ Q%% 2(/4)C$ &. %Q% $%&+,-.G#3! ) 11 &1Q% % (/ <6)C$ & ORG 1h for COM file. CALL p1 ADD AX, 1 return to DOS. p1 PROC procedure declaration. MOV AX, 1234h return to caller. p1 ENDP < L 6 / 9 C Q & if high bit of AL = 1 then AH = 255 (FFh) AH = MOV AX, AH =, AL = MOV AL, -5 AX = FBh (251) CBW AX = FFFBh (-5) < L 6 / 6

:: : :& :: %2<14%1%%& CF = < "? )%2? )14%1%%&6(?( C%< /6' < /68 '>?6'>?68 ' O6' O68 '66'668 %$% %%%& DF =? " ( $ %2( $ 14%1%%& % $C%% $& F = ( " %2<14 2) $ 4& if CF = 1 then CF = if CF = then CF = 1 < A 7

:) :)$ :)4 'AB AB ' T % % $&6$ C% Q%%) $ ) & operand1 - operand2 @'6@'L@'@'/@'<@%) & MOV AL, 5 MOV BL, 5 CMP AL, BL AL=5, ZF=1 (eit) < L 6 / B6D?(E?6D6(E% %%%& DS:[S] - ES:[D] @'6@'L@'@'/@'<@%) & if DF = then S = S + 1 D = D + 1 S = S - 1 D = D - 1 < L 6 / B6D?(E?6D6(E%9 %%%& DS:[S] - ES:[D] @'6@'L@'@'/@'<@%) & if DF = then S = S + 2 D = D + 2 S = S - 2 D = D - 2 < L 6 / 8

:4 P %9 9 & if high bit of AX = 1 then DX = 65535 (FFFFh) DX = MOV DX, DX = MOV AX, AX = MOV AX, -5 DX AX = h:fffbh CWD DX AX = FFFFh:FFFBh < L 6 / $ % $& P<? $ ) & if low nibble of AL > 9 or AF = 1 then AL = AL + 6 AF = 1 if AL > 9Fh or CF = 1 then AL = AL + 6h CF = 1 MOV AL, Fh AL = Fh (15) DAA AL = 15h < L 6 / S% % $& P<? Q% ) & if low nibble of AL > 9 or AF = 1 then AL = AL - 6 AF = 1 if AL > 9Fh or CF = 1 then AL = AL - 6h CF = 1 MOV AL, FFh AL = FFh (-1) DAS AL = 99h, CF = 1 < L 6 / 9

: & AB AB $& operand = operand - 1 MOV AL, 255 AL = FFh (255 or -1) DEC AL AL = FEh (254 or -2) < L 6 / <@ U P $& operand byte ise: AL = AX / operand AH = remainder (kalan) operand word ise: AX = (DX AX) / operand DX = remainder (kalan) MOV AX, 23 AX = CBh MOV BL, 4 DV BL AL = 5 (32h), AH = 3 < L 6 / R R R R R R / $%%& MOV AX, 5 HLT < L 6 / 1

&& & & AB AB >' & >'?= =' & ='?= P $& operand byte ise: AL = AX / operand AH = remainder (kalan) operand word ise: AX = (DX AX) / operand DX = remainder (kalan) MOV AX, -23 AX = FF35h MOV BL, 4 DV BL AL = -5 (CEh), AH = -3 (FDh) < L 6 / R R R R R R P Q$ $& operand byte ise: AX = AL * operand operand word ise: (DX AX) = AX * operand MOV AL, -2 MOV BL, -4 MUL BL AX = 8 < L 6 / R R R R 6Q$ <@V@V"%1%& > =C $ %& P)$ $ %%& 6 )$ $ &B,GG $?= C%%%& N AX, 4 get status of traffic lights. N AL, 7 get status of stepper-motor. < L 6 / 11

&: & & AB % $& operand = operand + 1 MOV AL, 4 NC AL AL = 5 L 6 / <@ U $ $C%Q% %%& 6)C$ C% <6 (/ (@V" / % %% $$ % MOV AH, Eh teletype. MOV AL, 'A' NT 1h BOS interrupt. < L 6 / ( " 19 %+ $.CQ% %& if OF = 1 then NT 4-5 - 127 = -132 (not in -128..127) the result of SUB is wrong (124), so OF = 1 is set: MOV AL, -5 SUB AL, 127 AL = 7Ch (124) NTO process error. 12

& < ( $ & Stack tan pop et: P CS flags register < L 6 / $$ B )$ ) % 2W $$4& P % % $& if (CF = ) and (ZF = ) then jump include 'emu886.inc' ORG 1h MOV AL, 25 CMP AL, 5 JA etiket1 PRNT 'AL 5 ten büyük deil' PRNT 'AL 5 ten büyük' < L 6 / 13

< <$ B )$ ) % 2 W $$4&P % % $& if CF = then jump include 'emu886.inc' ORG 1h MOV AL, 5 CMP AL, 5 JAE etiket1 PRNT 'AL is not above or equal to 5' PRNT 'AL is above or equal to 5' < L 6 / B )$ ) Q % 2W $$4& P % % $& if CF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 1 CMP AL, 5 JB etiket1 PRNT 'AL is not below 5' PRNT 'AL is below 5' < L 6 / 14

<$ <: B )$ ) Q % 2 W $$4&P % % $& if CF = 1 or ZF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 5 CMP AL, 5 JBE etiket1 PRNT 'AL is not below or equal to 5' PRNT 'AL is below or equal to 5' < L 6 / + % $& if CF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 255 ADD AL, 1 JC etiket1 PRNT 'tama yok' PRNT tama var' < L 6 / 15

<:=( < <= C%+ % $& if CX = then jump include 'emu886.inc' ORG 1h MOV CX, JCXZ etiket1 PRNT 'CX sıfır deildir.' PRNT 'CX sıfırdır.' < L 6 / B )$ )$ % 2W $ $4&P % % $& if ZF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 5 CMP AL, 5 JE etiket1 PRNT 'AL 5 e eit deil.' PRNT 'AL 5 e eit.' < L 6 / 16

<# <# B )$ ) % 2 W $$4&P % % $& if (ZF = ) and (SF = OF) then jump include 'emu886.inc' ORG 1h MOV AL, 5 CMP AL, -5 JG etiket1 PRNT 'AL -5 ten büyük deildir.' PRNT ' AL -5 ten büyüktür.' < L 6 / B )$ ) % 2 W $$4&P % % $& if SF = OF then jump include 'emu886.inc' ORG 1h MOV AL, 2 CMP AL, -5 JGE etiket1 PRNT 'AL < -5' PRNT 'AL >= -5' < L 6 / 17

< < B )$ ) Q % 2W $$4& P % % $& if SF <> OF then jump include 'emu886.inc' ORG 1h MOV AL, -2 CMP AL, 5 JL etiket1 PRNT 'AL >= 5.' PRNT 'AL < 5.' < L 6 / B )$ ) Q % 2 W $$4&P % % $& if SF <> OF or ZF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, -2 CMP AL, 5 JLE etiket1 PRNT 'AL > 5.' PRNT 'AL <= 5.' < L 6 / 18

< ) <. X% $&. +,-.G#3! &P ) 11 & always jump include 'emu886.inc' ORG 1h MOV AL, 5 JMP etiket1 jump over 2 lines! PRNT 'Not Jumped!' MOV AL, PRNT 'Got Here!' < L 6 / B )$ ) % 2W $4 $&P % % $& if CF = 1 or ZF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 2 CMP AL, 5 JNA etiket1 PRNT 'AL is above 5.' PRNT 'AL is not above 5.' < L 6 / 19

< <$ B )$ ) % 2W $4$&P % % $& if CF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 2 CMP AL, 5 JNAE etiket1 PRNT 'AL >= 5.' PRNT 'AL < 5.' < L 6 / B )$ ) Q % 2W $4 $&P % % $& if CF = then jump include 'emu886.inc' ORG 1h MOV AL, 7 CMP AL, 5 JNB etiket1 PRNT 'AL < 5.' PRNT 'AL >= 5.' < L 6 / 2

<$ <: B )$ ) Q % 2W $4$&P % % $& if (CF = ) and (ZF = ) then jump include 'emu886.inc' ORG 1h MOV AL, 7 CMP AL, 5 JNBE etiket1 PRNT 'AL <= 5.' PRNT 'AL > 5.' < L 6 / 2)14" % 2W $4$& if CF = then jump include 'emu886.inc' ORG 1h MOV AL, 2 ADD AL, 3 JNC etiket1 PRNT 'has carry.' PRNT 'no carry.' < L 6 / 21

< <# B )$ ) % 2W $4 $&P % % $& if ZF = then jump nclude 'emu886.inc' ORG 1h MOV AL, 2 CMP AL, 3 JNE etiket1 PRNT 'AL = 3.' PRNT 'Al <> 3.' < L 6 / B )$ ) % 2W $4 $&P % % $& if (ZF = 1) and (SF <> OF) then jump include 'emu886.inc' ORG 1h MOV AL, 2 CMP AL, 3 JNG etiket1 PRNT 'AL > 3.' PRNT 'Al <= 3.' < L 6 / 22

<# < B )$ ) % 2W $4$&P % % $& if SF <> OF then jump include 'emu886.inc' ORG 1h MOV AL, 2 CMP AL, 3 JNGE etiket1 PRNT 'AL >= 3.' PRNT 'Al < 3.' < L 6 / B )$ ) Q % 2W $4 $&P % % $& if SF = OF then jump include 'emu886.inc' ORG 1h MOV AL, 2 CMP AL, -3 JNL etiket1 PRNT 'AL < -3.' PRNT 'Al >= -3.' < L 6 / 23

< < B )$ ) Q % 2W $4$&P % % $& if (SF = OF) and (ZF = ) then jump include 'emu886.inc' ORG 1h MOV AL, 2 CMP AL, -3 JNLE etiket1 PRNT 'AL <= -3.' PRNT 'Al > -3.' < L 6 / 19 " % 2W $4$& if OF = then jump -5-2 = -7 (inside -128..127) the result of SUB is correct, so OF = : include 'emu886.inc' ORG 1h MOV AL, -5 SUB AL, 2 AL = F9h (-7) JNO etiket1 PRNT 'overflow!' PRNT 'no overflow.' < L 6 / 24

<) < /2 4" 2 4% 2W $4$& 6 ) $! &< /'6N '??' B6'?'A'=A % & if PF = then jump include 'emu886.inc' ORG 1h MOV AL, 111b AL = 7 OR AL, just set flags. JNP etiket1 PRNT 'parity even.' PRNT 'parity odd.' < L 6 / P 2 4+ 2$14% 2W $4 $&< /'6N '??'B6'?'A'=A % & if SF = then jump include 'emu886.inc' ORG 1h MOV AL, 111b AL = 7 OR AL, just set flags. JNS etiket1 PRNT 'signed.' PRNT 'not signed.' < L 6 / 25

<( < 6%1%2L@4" 2$14% 2W $4$& < /'6N '??'B6'?'A'=A % & if ZF = then jump include 'emu886.inc' ORG 1h MOV AL, 111b AL = 7 OR AL, just set flags. JNZ etiket1 PRNT 'zero.' PRNT 'not zero.' < L 6 / 19 2@4+ % 2W $4$& if OF = 1 then jump -5-127 = -132 (not in -128..127) the result of SUB is wrong (124), so OF = 1 is set: include 'emu886.inc' org 1h MOV AL, -5 SUB AL, 127 AL = 7Ch (124) JO etiket1 PRNT 'no overflow.' PRNT 'overflow!' < L 6 / 26

<) <) /2 4+ 2 Q14% 2W $4 $&6 ) $! &< /'6N '??'B6'?'A'=A % & if PF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 11b AL = 5 OR AL, just set flags. JP etiket1 PRNT 'parity odd.' PRNT 'parity even.' < L 6 / /Q1 2 4% 2W $4$&6 ) $! &< /'6N '??'B6'?'A'=A % & if PF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 11b AL = 5 OR AL, just set flags. JPE etiket1 PRNT 'parity odd.' PRNT 'parity even.' < L 6 / 27

<) < / 24% 2W $4$&6 ) $! &< /'6N '??'B6'?'A'=A % & if PF = then jump include 'emu886.inc' ORG 1h MOV AL, 111b AL = 7 OR AL, just set flags. JPO etiket1 PRNT 'parity even.' PRNT 'parity odd.' < L 6 / 6+ 2 14% 2W $4$&< /' 6N '??'B6'?'A'=A % & if SF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 1b AL = -128 OR AL, just set flags. JS etiket1 PRNT 'not signed.' PRNT 'signed.' < L 6 / 28

<( 9 B %1% 2L@V+4% 2W $4$&< /'6N '??' B6'?'A'=A % & if ZF = 1 then jump include 'emu886.inc' ORG 1h MOV AL, 5 CMP AL, 5 JZ etiket1 PRNT 'AL is not equal to 5.' PRNT 'AL is equal to 5.' < L 6 / 5 C% C%%21 4 $!C & AH = flags register AH: 7 6 5 4 3 2 1 [SF] [ZF] [] [AF] [] [PF] [1] [CF] 1, 3, 5 bitleri ayrılmıtır. < L 6 / 5 1%% 9 % 1$ C?6C & REG = first word DS = second word ORG 1h LDS AX, m m DW 1234h DW 5678h END AX is set to 1234h, DS is set to 5678h. < L 6 / 29

B1 1 & REG = adres of memory (offset) ORG 1h LEA AX, m m DW 1234h END =C "+". %& >B - 'AB + C%&"+"" %%Q C "+".& < L 6 / 5 1%% 9 % 1$ C B6C & REG = first word ES = second word ORG 1h LES AX, m m DW 1234h DWG#3! END = C%% +,-. B6 C%% G#3!& < L 6 / 3

$ 4 > C%?6D6(E &6( ) 2+%%%2?V"4'+%%2?V+44 AL = DS:[S] if DF = then S = S + 1 S = S - 1 ORG 1h LEA S, a1 MOV CX, 5 MOV AH, Eh m: LODSB NT 1h LOOP m a1 DB 'H', 'e', 'l', 'l', 'o' < L 6 / = C%?6D6(E 9 &6( ) 2,%%%2?V"4',%%2?V+44 AX = DS:[S] if DF = then S = S + 2 S = S - 2 ORG 1h LEA S, a1 MOV CX, 5 REP LODSW finally there will be 555h in AX. a1 dw 111h, 222h, 333h, 444h, 555h < L 6 / 31

) ) <=%% <=%1% %& CX = CX - 1 if CX <> then jump no jump, continue include 'emu886.inc' ORG 1h MOV CX, 5 PRNTN 'loop!' LOOP etiket1 < L 6 / <=%% <=%1% 2 $ %42L@V+4 & CX = CX - 1 if (CX <> ) and (ZF = 1) then jump no jump, continue Loop until result fits into AL alone, or 5 times. The result will be over 255 on third loop (1+1+1), so loop will exit. include 'emu886.inc' ORG 1h MOV AX, MOV CX, 5 PUTC '*' ADD AX, 1 CMP AH, LOOPE etiket1 < L 6 / 32

) )( <=%% <=%1% 2 $ %42L@V"4 CX = CX - 1 if (CX <> ) and (ZF = ) then jump no jump, continue Loop until '7' is found, or 5 times. include 'emu886.inc' ORG 1h MOV S, MOV CX, 5 PUTC '*' MOV AL, v1[s] NC S next byte (S=S+1). CMP AL, 7 LOOPNE etiket1 v1 db 9, 8, 7, 6, 5 < L 6 / <=%% <=%1% L@V" & CX = CX - 1 if (CX <> ) and (ZF = ) then jump no jump, continue Loop until '7' is found, or 5 times. include 'emu886.inc' ORG 1h MOV S, MOV CX, 5 PUTC '*' MOV AL, v1[s] NC S next byte (S=S+1). CMP AL, 7 LOOPNZ etiket1 v1 db 9, 8, 7, 6, 5 < L 6 / 33

)( 'AB AB ' 6 '6AB 6AB 6AB <=%% <=%1% L@V+ & CX = CX - 1 if (CX <> ) and (ZF = 1) then jump no jump, continue Loop until result fits into AL alone, or 5 times. The result will be over 255 on third loop (1+1+1), so loop will exit. include 'emu886.inc' ORG 1h MOV AX, MOV CX, 5 PUTC '*' ADD AX, 1 CMP AH, LOOPZ etiket1 < L 6 / P)$ )$ $%& O <6 (/ C% & P C%% % 2) Q% C% %%4& operand1 = operand2 ORG 1h MOV AX, B8h set AX = B8h (VGA memory). MOV DS, AX copy value of AX to DS. MOV CL, 'A' CL = 41h (ASC code). MOV CH, 111111b CL = color attribute. MOV BX, 15Eh BX = position on screen. MOV [BX], CX w.[b8h:15eh] = CX. returns to operating system. < L 6 / 34

$ 4?6D6(E B6D?(E $&6(?( C%) & ES:[D] = DS:[S] if DF = then S = S + 1 D = D + 1 S = S - 1 D = D - 1 ORG 1h LEA S, a1 LEA D, a2 MOV CX, 5 REP MOVSB a1 DB 1,2,3,4,5 a2 DB 5 DUP() < L 6 /?6D6(E B6D?(E 9 $&6(?( C%) & ES:[D] = DS:[S] if DF = then S = S + 2 D = D + 2 S = S - 2 D = D - 2 ORG 1h LEA S, a1 LEA D, a2 MOV CX, 5 REP MOVSW a1 DW 1,2,3,4,5 a2 DW 5 DUP() < L 6 / 35

# ) AB AB P Q$ $& operand byte ise: AX = AL * operand. operand word ise: (DX AX) = AX * operand. MOV AL, 2 AL = C8h MOV BL, 4 MUL BL AX = 32h (8) < L 6 / R R R R <@V@V"9 )1 & %% 2 4& nvert all bits of the operand Add 1 to inverted operand MOV AL, 5 AL = 5h NEG AL AL = FBh (-5) NEG AL AL = 5h (5) < L 6 / P $ & Do nothing do nothing, 3 times: NOP NOP NOP < L 6 / 36

AB 'AB AB ' & '> & '=?='>?='= $ 2 4& if bit is 1 turn it to. if bit is turn it to 1. MOV AL, 1111b NOT AL AL = 1111b < L 6 / P$ %%% Q % $&? 1 OR 1 = 1 1 OR = 1 OR 1 = 1 OR = MOV AL, 'A' AL = 11b OR AL, 1b AL = 111b ('a') < L 6 / " " R > = C% $ & P$ $ %%&B,GGC $?= C%%%& MOV AX, FFFh Turn on all OUT 4, AX traffic lights. MOV AL, 1b Turn on the third OUT 7, AL magnet of the stepper-motor. < L 6 / 37

)) )) ))9 AB 6AB 6)C+# % $ %& operand = SS:[SP] (stack ın en üstü) SP = SP + 2 MOV AX, 1234h PUSH AX POP DX DX = 1234h < L 6 / Q% C%2?('6('/'6/'='?=' <='=4)C$$ &6/ % & )!"+!# ) %%& POP D POP S POP BP POP xx (SP gözardı edilir) POP BX POP DX POP CX POP AX < L 6 / @ C%)C $$ & flags = SS:[SP] (top of the stack) SP = SP + 2 < L 6 / /$ 38

) ) )9 AB 6AB +# )C%& 6 +# )& /N65 )!"+!# ) %%& SP = SP - 2 SS:[SP] (top of the stack) = operand MOV AX, 1234h PUSH AX POP DX DX = 1234h < L 6 / Q% C%2='<='?='='6/' /'6('?(4)C$ &6/ C%%/N 65 ) %%& )!"+!# ) %%& PUSH AX PUSH CX PUSH DX PUSH BX PUSH SP PUSH BP PUSH S PUSH D < L 6 / @ C%)C& SP = SP - 2 SS:[SP] (top of the stack) = flags < L 6 / 39

: : ) ' '<> <> ' '<> <> ) )$ % %2)14 & %%)$ & shift all bits left, the bit that goes off is set to CF and previous value of CF is inserted to the right-most position. STC set carry (CF=1). MOV AL, 1Ch AL = 111b RCL AL, 1 AL = 1111b, CF=. < @V" )$ & )$ % %2)14 & %%)$ & shift all bits right, the bit that goes off is set to CF and previous value of CF is inserted to the left-most position. STC set carry (CF=1). MOV AL, 1Ch AL = 111b RCR AL, 1 AL = 1111b, CF=. < @V" )$ & O6' O68 '>?6'>?68 '66'668 %%<= 1 & check_cx: if CX <> then do following chain instruction CX = CX - 1 go back to check_cx exit from REP cycle L 4

) ) )( ) ) ) < /6'< /68 '6<6'6<68 %%L@V+ ) 2Q 4 1<= & check_cx: if CX <> then do following chain instruction CX = CX - 1 if ZF = 1 then m go back to check_cx m exit from REPE cycle exit from REPE cycle L < /6'< /68 '6<6'6<68 %%L@V" ) 2Q 4 1<= & check_cx: if CX <> then do following chain instruction CX = CX - 1 if ZF = then go back to check_cx m exit from REPNE cycle exit from REPNE cycle L < /6'< /68 '6<6'6<68 %%L@V" ) 2Q %1% 4 1<= & check_cx: if CX <> then do following chain instruction CX = CX - 1 if ZF = then m go back to check_cx m exit from REPNZ cycle exit from REPNZ cycle L 41

)( 9 ) < /6'< /68 '6<6'6<68 %%L@V+ ) 2Q %1%4 1<= & check_cx: if CX <> then do following chain instruction CX = CX - 1 if ZF = 1 then go back to check_cx exit from REPZ cycle exit from REPZ cycle L $ $& Pop from stack: P if immediate operand is present: SP = SP + operand ORG 1h for COM file. CALL p1 ADD AX, 1 return to OS. p1 PROC procedure declaration. MOV AX, 1234h return to caller. p1 ENDP < L 6 / @$ $& Pop from stack: P CS if immediate operand is present: SP = SP + operand < L 6 / 42

9 ' '<> <> ' '<> <> )$ %& %%)$ & shift all bits left, the bit that goes off is set to CF and the same bit is inserted to the right-most position. MOV AL, 1Ch AL = 111b ROL AL, 1 AL = 111b, CF=. < @V" )$ % & )$ %& %%)$ & shift all bits right, the bit that goes off is set to CF and the same bit is inserted to the left-most position& MOV AL, 1Ch AL = 111b ROR AL, 1 AL = 111b, CF=. < @V" )$ % & 5 C%1 C%% $!C & flags register = AH AH bit:7 6 5 4 3 2 1 [SF] [ZF] [] [AF] [] [PF] [1] [CF] 1, 3, 5 bitler ayrılmıtır. < L 6 / 43

$$ ' '<> <> ' '<> <> 'AB AB ' )$ % %%&T% %%) $ & Shift all bits left, the bit that goes off is set to CF. Zero bit is inserted to the right-most position. MOV AL, Eh AL = 111b SAL AL, 1 AL = 11b, CF=1. < @V" )$ & )$ % %%&T% %%) $ & Shift all bits right, the bit that goes off is set to CF. The sign bit that is inserted to the left-most position has the same value as before shift. MOV AL, Eh AL = 111b SAR AL, 1 AL = 1111b, CF=. MOV BL, 4Ch BL = 111b SAR BL, 1 BL = 111b, CF=. < Q Q% $& operand1 = operand1 - operand2 - CF STC MOV AL, 5 SBB AL, 3 AL = 5-3 - 1 = 1 < L 6 / 44

:$ :4 ' '<> <> > B6D?(E % %%& ES:[D] - AL set flags according to result: OF, SF, ZF, AF, PF, CF if DF = then D = D + 1 D = D - 1 < L 6 / = B6D?(E % %%& ES:[D] - AX set flags according to result: OF, SF, ZF, AF, PF, CF if DF = then D = D + 2 D = D - 2 < L 6 / )$ %%%&T% %%)$ & Shift all bits left, the bit that goes off is set to CF. Zero bit is inserted to the right-most position. MOV AL, 111b SHL AL, 1 AL = 11b, CF=1. < @V" )$ & 45

: & ' '<> <> )$ %%%&T% %%)$ & Shift all bits right, the bit that goes off is set to CF. Zero bit is inserted to the left-most position. MOV AL, 111b SHR AL, 1 AL = 11b, CF=1. < @V" )$ & %2)14 & CF = 1 < + Y%2 )14 &< /6'< /68 '>?6'>?68 ' O6' O68 '66'668 %1%6(?(%% 2?V+4 %%%2?V"4& DF = 1? + T %2 $14 &% $C%% $& F = 1 ( + 46

$ 4 > C%% B6D?(E $&?() & ES:[D] = AL if DF = then D = D + 1 D = D - 1 ORG 1h LEA D, a1 MOV AL, 12h MOV CX, 5 REP STOSB a1 DB 5 dup() < L 6 / = C%% B6D?(E $&?() & ES:[D] = AX if DF = then D = D + 2 D = D - 2 ORG 1h LEA D, a1 MOV AX, 1234h MOV CX, 5 REP STOSW a1 DW 5 dup() < L 6 / 47

$ =:# 'AB AB ' 'AB AB ' 'AB AB S% $& operand1 = operand1 - operand2 MOV AL, 5 SUB AL, 1 AL = 4 < L 6 / P$ % %%% $ & $ % L@'6@ /@ &? 1 AND 1 = 1 1 AND = AND 1 = AND = MOV AL, 11b TEST AL, 1 ZF =. TEST AL, 1b ZF = 1. < L 6 / " " P$ % & operand1 < - > operand2 MOV AL, 5 MOV AH, 2 XCHG AL, AH AL = 2, AH = 5 XCHG AL, AH AL = 5, AH = 2 < L 6 / 48

= $ = 'AB AB ' Q &?6D=F >E > C%$& AL = DS:[BX + unsigned AL] ORG 1h LEA BX, dat MOV AL, 2 XLATB AL = 33h dat DB 11h, 22h, 33h, 44h, 55h < L 6 / P$ % %%% =A $%%&6Q) $ %&? 1 XOR 1 = 1 XOR = 1 XOR 1 = 1 XOR = MOV AL, 111b XOR AL, 1b AL = 11b < L 6 / " " R 49

hafizada yeralan ve herbirisi 2 rakamdan olusan 16'lik tabandaki iki sayinin toplamini yapar. ilk sayi 1h-19h ikinci sayi 1Ah-113h sonuc 114h-11Dh m.ali akcayol 1.7.27 org 1h mov [1h],8A76h mov [12h],6557h mov [14h],1A98h mov [16h],713Eh mov [18h],8797h mov [1Ah],2587h mov [1Ch],8B96h mov [1Eh],2588h mov [11h],46D1h mov [112h],9854h mov si, 18h 1.sayinin en sagdaki 4 rakam (1 word) aliniyor mov bx,[si] add bx,[si+ah] 2.sayinin en sagdaki 4 rakami ile toplaniyor mov [si+14h],bx sonuc hafizaya yaziliyor jnc atla1 carry= ise atla mov dx,1 sub isleminden once carry dx'e saklaniyor atla1: sub si,2 sola dogru 4 rakam (1 word) gidiliyor dongu: mov bx,[si] 1.sayinin onceki 4 rakami (1 word) aliniyor add bx,[si+ah] 2.sayinin onceki 4 rakami ile toplaniyor add bx,dx varsa carry ekleniyor xor dx,dx saklanan carry degeri sifirlaniyor mov [si+14h],bx sonuc hafizaya yaziliyor jnc atla2 carry= ise atla mov dl,1 atla2: sub si,2 sola dogru 4 rakam (1 word) gidiliyor cmp si,1h en sola gelindimi? jae dongu gelinmediyse basa doner call mesajyaz hlt mesajyaz proc mov dx, offset mesajvar mov ah, 9 int 21h ret mesajvar db "toplama islemi tamamlandi... $" mesajyaz endp 5

hafizada yeralan toplam 1 karakterden ADET ile belirtilen kadarini kendi yerinde siralayan algoritma - bubblesort m.ali akcayol 28.6.27 org 1h dizi db 'v','a','z','b','t','r','z','k','m','a' dizi1 db 'v','a','z','b','t','r','z','k','m','a' dizi2 db 'v','a','z','b','t','r','z','k','m','a' dizi3 db 'v','a','z','b','t','r','z','k','m','a' dizi4 db 'v','a','z','b','t','r','z','k','m','a' dizi5 db 'v','a','z','b','t','r','z','k','m','a' dizi6 db 'v','a','z','b','t','r','z','k','m','a' dizi7 db 'v','a','z','b','t','r','z','k','m','a' dizi8 db 'v','a','z','b','t','r','z','k','m','a' dizi9 db 'v','a','z','b','t','r','z','k','m','a' ADET dw 9 mov dx,adet call ekranayazdir ilk 1 karakter siralanir eleman sayisi-1 dongu: toplam eleman sayisi kadar tekrar mov cx, siralanmamis eleman sayisi icdongu: kalan eleman sayisi kadar tekrar mov si,cx mov al,[dizi+si] soldaki eleman mov bl,[dizi+si+1] sagdaki eleman cmp al,bl jbe devam soldaki kucukse degistrme yapma call degistir soldaki buyukse degistir devam: inc cx siralanmamis elemanlarda bir artir cmp cx,dx siralanmamis elemanlarin sonuna geldimi jnb icdongusonu siralanmamis elemanlarin sonu jmp icdongu siralanmamis eleman devam ediyor icdongusonu: ic dongude siralanmamis eleman kalmadi dec dx sirasiz kalan eleman sayisini bir azalt cmp dx, sirasiz eleman sayisi mi? je bitir sirasiz eleman sayisi ise bitir jmp dongu sirasiz eleman varsa basa git bitir: call ekranayazdir sirali yazdir hlt program bitisi degistir proc mov [dizi+si],bl mov [dizi+si+1],al ret degistir endp yanyana iki karakter yer degistirir ekranayazdir proc push dx dl ye deger atanacak mov cx, karakter sayaci mov ah, 2 int 21, ah=2, ekrana karakter yazdir tekrar: 51

mov si,cx mov dl, [dizi+si] int 21h inc cx cmp cx, ADET ja cikis jmp tekrar cikis: mov dl, Dh int 21h mov dl, Ah int 21h pop dx ret ekranayazdir endp int 21, ah=2, ekrana karakter yazdir return yeni satir dl nin eski degeri alindi 52

binary search --- sirali bir dizide en cok log(2)sayiadedi kadar kontrolle aranan sayinin olup olmadigini bulur m.ali akcayol 29.6.27 org 1h mov [1h], 1 mov [11h], 2 mov [12h], 3 mov [13h], 4 mov [14h], 6 mov [15h], 8 mov [16h], 9 mov [17h], 1 mov [18h], 11 mov [19h], 13 mov [1Ah], 14 mov [1Bh], 15 mov [1Ch], 16 mov [1Dh], 17 mov [1Eh], 19 mov [1Fh], 2 mov [11h], 22 mov [111h], 23 mov [112h], 25 mov [113h], 27 mov [114h], 28 mov [115h], 3 mov dl,2 bolen mov dh,28 aranan sayi mov bx,1h en kucuk adres mov cx,115h en buyuk adres mov si,1h mov ax,cx eleman sayisi hesaplaniyor dec bx sub ax,bx div dl ortadaki sayi bulunuyor xor ah,ah kalan atiliyor add si,ax ortadaki sayinin adresi dongu: cmp [si],dh ortadaki sayi arananla karsilastiriliyor jb sagtaraf kucukse saga gidilir ja soltaraf buyukse sola gidilir je bulundu esitse bulunmustur sagtaraf: mov bx,si mov ax,cx eleman sayisi hesaplaniyor sub ax,bx div dl ortadaki sayi bulunuyor cmp al, jz kalanal1 xor ah,ah kalan atiliyor add si,ax ortadaki sayinin adresi 53

jmp dongu kalanal1: xchg al,ah add si,ax cmp [si],dh je bulundu jne sayiyok soltaraf: mov cx,si mov ax,cx sub ax,bx div dl cmp al, jz kalanal2 xor ah,ah sub si,ax jmp dongu kalanal2: xchg al,ah sub si,ax cmp [si],dh je bulundu jne sayiyok basa don son kalan eleman kontrol ediliyor eleman sayisi hesaplaniyor ortadaki sayi bulunuyor kalan atiliyor ortadaki sayinin adresi basa don son kalan eleman kontrol ediliyor yazdirma islemleri bulundu: mov dx, offset mesajvar mov ah, 9 int 21h ret mesajvar db "sayi bulundu $" jmp cikis sayiyok: mov dx, offset mesajyok mov ah, 9 int 21h ret mesajyok db "sayi yok $" cikis: hlt 54