Sunteți pe pagina 1din 17

Assembly Language Lecture Notes

The heart of a personal computer is a microprocessor, which handles the computers requirements for arithmetic, logic, and control. The microprocessor had its origin in the 1960s, when research designers devised the integrated circuits(IC) by combining various electronic components into a single component on a silicon chip. In 1971, Intel released the world's first microprocessor- the 4004, a 4-bit microprocessor. Later in 1971, Intel introduced the 8008 chip (an 8-bit microprocessor), which ushered in the first generation of microprocessors. By 1974, the 8008 had evolved into the 8080, a popular second-generation microprocessor with general-purpose use. A newer version of 8080, the 8085, was introduced in 1977. In 1978, Intel produced the third-generation 8086 processor (a 16-bit microprocessor), which provided some compatibility with the 8080 and represented a significant advance on its design. Next, Intel developed the 8088 (1979), a variation of the 8086 that provided a slightly simpler design and compatibility with then-current input/output devices. An enhanced version of the 8088 is the 80188, and enhanced version of the 8086 are the 80186, 80286, 80386, 80486, Pentium (or 586), PentiumPro (or 6x86) each of which provides additional operations and processing power. Each family of processors has its own unique set of instructions that are used to direct operations, such as accept input from keyboard, display data on screen, and perform arithmetic. This set of instructions is known as the systems machine language, which is too complex and obscure for developing programs. Software suppliers provide an assembly language for the processor family that represents the various instructions in a more understandable symbolic code. The use of assembly language provides a number of advantages: A program written in assembly language requires considerably less memory and execution time than a program written in a high-level language. Assembly language gives the programmer the ability to perform highly technical tasks that would be difficult, if not possible, in a high-level language. A knowledge of assembly language provides an understanding of machine architecture that no high-level language can ever provide. Resident programs (that reside in memory while other programs execute) and interrupt service routines (that handle input and output) are almost always developed in assembly language. Writing a program in assembly language requires knowledge of the computers hardware (or architecture) and the details of its instruction set. The main internal hardware features of a computer are the microprocessors, memory, and registers; external hardware features are the computers input/output devices such as the keyboard, monitor, and disk. Software consists of the various programs and data files (including the operating system) stored on the disk. To execute a program, the system copies it from disk to internal memory. (Internal memory is what people claim that their computer has 16 Megabytes of memory). The microprocessor executes the program instructions, and the registers handle the requested arithmetic, data movement, and addressing. Bit the fundamental building block of computer storage. Byte a group of 8 bits. - 8 bits allow 256 different combinations of on-off conditions - it is used as the basis for binary arithmetic and for representing such characters as the letter A Word a 2-byte (16 bit) data item Doubleword a 4-byte (32 bit) data item Quadword an 8-byte (64 bit) data item Paragraph a 16-byte (128 bit) area. Kilobyte (KB) the number 210 equals 1,024, which happens to be the value K, for kilobyte. Megabyte (MB) the number 220 equals 1,048,576, or 1 megabyte

USING THE DEBUG PROGRAM Debug can only create files with a .COM extension, and because of the characteristics of these kinds of programs they cannot be larger that 64KB, and they must start with displacement, offset, or 0100H memory direction inside the specific segment. Debug commands: A Assemble symbolic instructions into machine code D Display the contents of an area of memory E Enter data into memory, beginning at specific location G Run the executable program in memory N Name a program P Proceed, or execute a set of related instructions Q Quit the DEBUG session R Displays the contents of one or more registers T Trace the execution of one instruction U Unassemble machine code into symbolic code W Write a program onto disk Debug Rules: it does not distinguish between lowercase and uppercase letters you enter a space only where it is needed to separate parameters in a command assumes that all numbers are in hexadecimal format Workshop#1: Viewing Memory Locations Use Debug program to do the following 1. Checking System Equipment Note: Reverse the first 2 bytes and convert them to binary Example: 63 and 44 will become 4463 Bits Device 15,14 Number of parallel printer ports attached 11.9 Number of serial ports attached 7,6 Number of diskette devices (where 00=1, 01=2, 10=3, 11=4) 5,4 Initial video mode (where 01=40x25 color, 10=80x25 color, 11=80x25 monochrome) 1 math coprocessor present 0 diskette drive is present 2. Type: D 40:10 (and press enter) Checking Memory Size Type: D 40:13 (and press enter) Note: Reverse first 2 bytes and convert to decimal Example: 8002H is 0280H which is equal to 64K Checking Serial Number and Copyright Notice Type: D FE00:0 (and press enter) Note: just press D to continue the display Checking ROM BIOS Date Type: D FFFF:5 (and press enter) Checking Model ID Type: D FFFF:E (and press enter) Code Model F8 PS/2 models 70 and 80 FA PS/2 model 30 FB PC-XT (1986) FC PC-AT(1984), PC-XT model 286, PS/2 models 50 and 60, etc. FE PC-XT(1982), portable(1982)

3. 4. 5.

FF Original IBM PC The INT Instruction On execution, an INT instruction interrupts processing and accesses the interrupt services table in low memory to determine the address of a required routine. The operation then transfers to DOS or to BIOS for specified action and returns to your program to resume processing MOV Instruction The MOV instruction transfers(that is, copies) data referenced by address of the second operand to the address of the first operand. The sending field is unchanged. The operands that reference memory or registers must agree in size. Format: MOV register/memory, register/memory/immediate Example: Immediate to registerMOV AX,25 Immediate to memory MOV BYTEVAL,25 Register to Register MOV AX,BX Register to Memory MOV BYTEVAL,BH Memory to Register MOV BH,BYTEVAL Interrupt 21H for keyboard input - insert a service call in the AH register service 1 Keyboard input with echo The operation accepts a character from the keyboard buffer or waits for a keyboard entry. The value/character entered is stored in AL 2 Display output Useful for displaying single character. Load into DL the character that is to display at the current cursor position, and request Int 21H 9 Display string It requires definition of a display character string in the data area, immediately followed by a dollar sign delimiter, which the operation uses to end the display. 0A Buffered keyboard input The input area for keyed-in characters requires a parameter list containing specified fields that the INT operation is to process. Steps: To create program A 100 To save program N filename.com name the program RCX store the size to CX W write to disk To load program N filename.com name the program L load U <starting add> <final add> unassemble Sample programs: 1. Display character A on screen MOV AH,02 ; service to MOV DL,41 ; A on data register INT 21 ; display output INT 20 ; return to DOS 2. Input a character from user MOV AH,01 ;request keyboard input INT 21 ; accept input

INT 20

; return to DOS

Exercises: 1. Write an assembly language program that will accept a character from the user and displays back the character on screen. 2. Modify exer1.com so that the character will be displayed back on screen 5 times. Sample Program: 1. Program to display Hello, World on screen 100 mov ah,09 ; display string 103 mov dx,109 ; move into dx immediate address 105 int 21 ; display 107 int 20 ; return to DOS 109 db Hello, World $ ; db define byte 2. Program to accept entry 100 mov dx,109 103 mov ah,0a 105 int 21 107 int 20 109 db 5

; buffered keyboard input

Exercise: 1. Write an assembly language program that will ask the user to enter his/her name. Sample output: Enter your name: __________ Entry for user INT 10 for Video Display Accepts a number of service calls in the AH for screen mode, setting the cursor, scrolling, and displaying Service: 1 Set cursor size MOV AH,01 MOV CH,04 MOV CL,08 INT 10 INT 20 2

; start scan line in CH ; end scan line in CL

Set cursor position MOV AH,02 MOV BH,00 ;page number MOV DH,{row value} ; in HEX MOV DL,{col value} ; in HEX INT 10 INT 20 Scroll-Up Screen MOV AX,0605 MOV BH,07 MOV CX,0A1C MOV DX,0E34 INT 10 ;scroll 5 lines ; 00 if full screen ;color attribute background/foreground ; from row 10 column 28 ;to row 14 column 52

INT 20 Exercises: 1. Write an assembly language program that will display a message Enter your name at row 12 column 25. The user will be allowed to enter a maximum of 25 characters for name and will display on row 15 column 10 a message Hello {name}, where name is the data that the user entered. You should format your screen first so that at run-time, the screen is initially empty. Program Logic and Control 4 classes of transfer operations - unconditional jump JMP - looping LOOP - conditional jump Jnnn (such as JE, JA, etc) - call a procedure CALL Unconditional jumps: JMP Instruction - commonly used instruction for transferring control; it is unconditional since the operation transfers control under all circumstances. Conditional jumps: Jumps for equalityJCXZ tests the contents of the CX register for zero JE/JZ Jump equal or jump zero JNE/JNZ Jump not equal or jump not zero Jumps based on unsigned comparisonsJA/JNBE Jump above or Jump not below equal JAE/JNB Jump above/equal or jump not below JB/JNAE Jump below or jump not above/equal JBE/JNA Jump below/equal or jump not above Jumps based on signed comparisonsJG/JNLE Jump greater or jump not less/equal JGE/JNL jump greater/equal or jump not less JL/JNGE Jump less or jump not greater/equal JLE/JNG Jump less/equal or jump not greater Counting Instructions 1. DEC instruction - decrease the operator 2. INC instruction - increase the operator Comparison Instructions 1. CMP Instruction - compare the operators CMP destiny, source - this instruction subtracts the source operator from the destiny operator but without this one storing the result of the operation Sample Program: 1. This is a program to display on the screen 15 times a character string 100 mov dx,111 ;copies string to dx register 103 mov cx,000F ; # of times the string will be displayed 106 mov ah,09 ; display string service 108 int 21 ; display string

10A 10B 10D 10F 111

dec cx ; reduces 1 in cx jcxz,10F ; if cx is equal to zero, jump to 10F jmp 108 ; jumps to direction 108 int 20 ; ends the program db Hello, World! 0D 0A $

Exercise: 1. The sample program above displays the string using a counter starting from F to 0. Modify the program so that it will use a counter starting from 0 to F. The output would still be the same.

Using an assembler in making assembly language programs


Comments: Block comments begins with the directive COMMENT and a user-specified symbol. All subsequent lines of text are ignored by the assembler until the same user-specified symbol appears. Ex. COMMENT ! This line is a comment. This line is also a comment. ! COMMENT & This line is a comment. This line is also a comment. &

Line comments- comment begins with a semicolon (;), and wherever you code it, the assembler assumes that all characters on the line to its right are comments. Example: ; this is a comment Reserved Words: instructions, such as MOV and ADD, which are operations that the computer can execute directives, such as END or SEGMENT, which you use to provide information to the assembler; It is a command that is recognized and acted upon by the assembler as the programs source code is being assembled. They are part of the assemblers syntax but are not related to the Intel instruction set. operators, such as FAR or SEGMENT, which you use in expressions predefined symbols, such as @DATA and @MODEL, which return information to your program

Identifiers: An identifier is a programmer-chosen name. It might identify a variable, a constant, a procedure or a code label. Labels: A label is an identifier that acts as a place marker for either instructions or data. Code labels- A label in the code area of a program and must end with a colon ( : ) character. In this context, labels are often used as targets of jumping and looping instructions. They may contain between 1 to 247 characters. They are not case sensitive. The 1st character must be either a letter, underscore, @, or $. Subsequent characters may also be digits. An identifier cannot be the same as an assembler reserved word.

Ex. Target: mov ax,bx Jmp target Data labelsEx. If a label is used in the data area of a program, it cannot end with a colon.

First DB 10 Segment Directives: the assembler provides some shortcuts in defining segments. To use them, you have to initialize the memory model before defining any segment. The general format (including the period) is: .model memory-model the general format (including the leading period) for the directives that define the stack, data, and code segments are: .stack .data .code Note: The instructions you now use to initialize the address of a data segment is the DS are: MOV AX,@DATA MOV DS,AX

Assembling, Linking and Running Programs


Programs written in assembly language cannot be executed directly. It must be translated, or assembled into executable code. The assembler produces a file containing machine language called an object file. This file is not ready to execute. It must be passed to another program called a linker, which in turn produces an executable file. This file is ready for execution in the prompt. The Assemble-Link-Execute Cycle The process of editing, assembling, linking and executing assembly language programs is summarized in the figure below. Link Library (assembler ) (linke r)

Source File

Object File

Executable File

(OS loader) Outp ut

(text editor)

Listing File

Map File

Here is a detailed description of each step: Step 1: A programmer uses a text editor to create an ASCII text file named the source file.

Step 2: The assembler reads the source file and produces an object file, a machine-language translation of the program. Optionally, it produces a listing file. If any errors occur, the programmer must return to step 1 and fix the program. Step 3: The linker reads the object file and checks to see if the program contains any calls to procedures in a link library. The linker copies any required procedures from the link library, combines them with the object file, and produces the executable file. Optionally, the linker can produce a map file. Step 4: The OS loader utility reads the executable file to memory, branches the CPU to the programs starting address, and the program begins to execute. Files Object file A machine-language translation of the program. Listing file A file that contains a copy of the programs source code, suitable for printing, with line numbers, offset addresses, translated in machine code, and a symbol table. Map file - A text file (extension MAP) that contains information about the segments contained in a program being linked. Offset and LEA LEA - Load Effective Address - Loads a near (offset) address into a register - LEA register,memory OFFSET returns the offset address ( that is, the relative address within the data segment or code of a variable or label. Instructions for ending program execution: MOV AH,4CH ; request end processing INT 21H ; call interrupt service

segment)

Sample Programs: 1. This a program to change cursor size .MODEL SMALL .STACK .CODE MOV AH,01H MOV CX,0408H INT 10H MOV AH,4CH INT 21H END

2.

This is a program that will accept a character and display the character back on screen .MODEL SMALL .STACK .CODE MOV AH,01H INT 21H MOV AH,02H MOV DL,AL INT 21H MOV AH,4CH INT 21H END Program to clear screen and set cursor position .MODEL SMALL .STACK .DATA .CODE MOV AX,0600H ;CLEAR SCREEN MOV BH,30 MOV CX,0000H MOV DX,184FH INT 10H MOV DX,040BH MOV AH,02H MOV BH,00 INT 10H MOV AH,4CH INT 21H END ;SET CURSOR

3.

;EXIT TO DOS

4.

Program to display on screen a character string .MODEL SMALL .STACK .DATA MYMSG DB Hello World! $ .CODE MOV AX,@DATA MOV DS,AX MOV AH,09H MOV DX,OFFSET MYMSG INT 21H MOV AH,4CH INT 21H END

5.

Program to input a string .MODEL SMALL .STACK .DATA MYVAR LABEL BYTE VARLEN DB 20 ACTLEN DB ? VARPTR DB 20 DUP( ),$ .CODE MOV AX,@DATA MOV DS,AX MOV AH,0AH MOV DX,OFFSET MYVAR INT 21H MOV AH,4CH INT 21H END Program to display inputted string .MODEL SMALL .STACK .DATA MYVAR LABEL BYTE VARLEN DB 20 ACTLEN DB ? VARPTR DB 20 DUP( ),$ .CODE MOV AX,@DATA ;INITIALIZE SEGMENT REGISTER MOV DS,AX MOV AH,0AH ;INPUT STRING MOV DX,OFFSET MYVAR INT 21H MOV BH,00H ;PUT TERMINATING CHARACTER MOV BL,ACTLEN MOV VARPTR[BX],$ MOV AH,09H ;DISPLAY STRING MOV DX,OFFSET VARPTR INT 21H MOV AH,4CH INT 21H END ;TERMINATE TO DOS

6.

Exercise: Write an assembly language program that will ask the user to enter his/her name at row 10 column 20 and then display a message with the entered name as part of the message. Sample output: Enter your name: Lee Hello, Lee

Procedures Syntax: <procedure-name> PROC <statement-1> : : <statement-n> <procedure-name> ENDP Note: to invoke procedure : CALL <proc-name> To return to the calling procedure: RET Example: .MODEL SMALL .STACK .DATA .CODE MAIN PROC CALL CLEAR_SCREEN MOV AH,4CH INT 21H MAIN ENDP CLEAR_SCREEN PROC : : ; WRITE YOUR STATEMENTS HERE : CLEAR_SCREEN ENDP END Loop - checks for the value of CX until it is equal to 0. It automatically decrements CX. Sample program: This program will display letter a 10 times Sol #1: using Jump (conditional) MOV CX,0AH A20: MOV AH,02H MOV DL, _____ ;store in DL the value of a INT 21H DEC CX CMP CX,00 JNE A20 MOV AH,4CH INT 21H Sol #2: using Loop MOV CX,0AH A20: MOV AH,02H MOV DL, _____ INT 21H LOOP A20 MOV AH,4CH INT 21H

;store here the value of a

Exercises: 1. Write an assembly language program that will keep on asking the user to enter a character until the user presses the enter key. Your program should clear the screen first, display an appropriate message to prompt the user for entry, and position your cursor at an appropriate area on the screen. Boolean Operators - use to clear and set bits and to handle ASCII data for arithmetic purposes General Format: operation {register/memory},{register/memory/immediate} AND OR XOR Example: AND 0101 0011 -----0001 - if matched bits are both 1, sets the result to 1. All other conditions result in 0 - if either (or both) of the matched bits is 1, sets the result to 1 otherwise result is 0 - if one matched bit is 0 and the other is 1, sets the result to 1. If matched bits are the same (both 0 or both 1), the result is 0 OR 0101 0011 --------0111 XOR 0101 0011 --------0110

for the following unrelated examples, assume AL = 11000101 BH = 01011100 1. AND AL,BH ; sets AL to 01000100 2. OR BH,AL ; sets BH to 11011101 3. XOR AL,AL ; sets AL to 00000000 4. AND AL,00 ; sets AL to 00000000 5. AND AL,0FH ; sets AL to 00000101 Sample Program: This program will convert lower case letters to upper case. Hint: A -> 41H = 01000001 a -> 61H = 01100001 Z -> 5AH = 01011010 z -> 7AH = 01111010 Note: The only difference is that the 5th bit is 0 in uppercase and 1 in lowercase. .MODEL SMALL .STACK .DATA MYTITLE DB Change To$ .CODE MOV AX,@DATA MOV DS,AX LEA BX,MYTITLE MOV CX,09 B20: MOV AH,[BX] CMP AH,61H JB B30 CMP AH,7AH JA B30 AND AH,11011111B MOV [BX],AH B30:

INC BX LOOP B20 MOV AH,09 LEA DX ,MYTITLE INT 21H MOV AH,4CH INT 21H END DATA Definition: Syntax: Name Dn expr Where: Name name of an item Dn directives that define data items, each of which explicitly indicates the length of the defined item DB byte DW word DD doubleword expr define an uninitialized value or an initial constant Example: Uninitialized item Initialized item FLDA FLDB DB ? DB 25

Character Strings Are used for descriptive data The string is defined within single or double quotes DB (Byte) is the only format that defines a character string and is the conventional format for defining character data of any length. Example: XXXX db "Crazy Sam's CD" YYYY db 'Crazy Sam''s CD' Numeric Constants Are used to define values and memory addresses. It is not defined within quotes but is followed by an optional radix specifier such as H for Hex, B for Binary, and optional D for Decimal Directives for Defining Data DB (Byte): Define Byte The maximum of one byte means two hex digits. The largest 1-byte number is hex FF, or 255. In terms of decimal numbers, these limits are +127 and -128 DW (Word): Define Word The largest positive 1-word hex number is 7FFF; all higher numbers, 8000 through FFFF represent negative values. In terms of decimal numbers, the limits are +32,767 and -32,768 DD (Doubleword): Define Doubleword The largest positive doubleword hex number is 7FFFFFFF; all higher numbers,80000000 through FFFFFFFF represent negative values. In terms of decimal numbers, these maximums are +2,147,483,647 and -2,147,483,648. DQ (Quadword): Define Quadword The largest positive quadword hex number is 7FFFFFFFFFFFFFFF; As an indication of the magnitude of this number, 1FFFFFFFFFFFFFFF equals the decimal number 1,152,921,504,606,846,976. Equate Directive

EQU: Defines a value that the assembler can use to substitute in other instructions. Example: FACTOR EQU 10 (Constant value) Addition and Subtraction The ADD and SUB instruction perform simple addition and subtraction of binary data. Format: ADD/SUB register,register ADD/SUB memory,register ADD/SUB register,memory ADD/SUB register,immediate ADD/SUB memory,immediate Sample Program: This program will ask the user to enter 2 numbers in the range of 0-4. It will then display the sum of the 2 numbers entered. .MODEL SMALL .STACK .DATA MSG1 DB 10,13, Enter First Number $ MSG2 DB 10,13, Enter Second Number $ NUM1DB 0 NUM2DB 0 .CODE MOV AX,@DATA MOV DS,AX ENT1: MOV DX,OFFSET MSG1 ;display prompt for first number MOV AH,09H INT 21H MOV AH,01H ;input first number INT 21H CMP AL,0 ;check if it is in range from 0 - 4 JB ENT1 CMP AL,4 JA ENT1 SUB AL,30H ;convert to real number entered MOV NUM1,AL ENT2: MOV DX,OFFSET MSG2 ;display prompt for second number MOV AH,09H INT 21H MOV AH,01H ;input second number INT 21H CMP AL,0 ;check if it is in range from 0 - 4 JB ENT1 CMP AL,4 JA ENT1 SUB AL,30H ;convert to real number entered MOV NUM2,AL MOV AL,NUM1 ; store into AL first number entered ADD AL,NUM2 ; add into AL second number entered, result is in AL ADD AL,30H ; convert the sum to char MOV AH,02H ; display the sum MOV DL,AL

INT 21H MOV AH,4CH ; exit to DOS INT 21H END MULTIPLICATION Format: MUL register/memory Basic multiplication operations: 1. Byte x Byte - the multiplicand is in the AL register, and the multiplier is a byte in memory or another register. The generated product is in the AX register and the operation ignores and erases any data that may be in the AH. 2. Word x Word - the multiplicand is in the AX register and the multiplier is a word in memory or another register. The product is a double word that requires two registers: the high-order(leftmost) portion in the DX and the low-order(rightmost) portion in the AX. The operation ignores and erases any data that may already be in the DX.

Example: Instruction Multiplier Multiplicand Product ===================================================== MUL CL BYTE AL AX MUL BX WORD AX DX:AX MUL EBX DWORD EAX EDX:EAX (DWORD x DWORD) DIVISION Format: DIV register/memory Basic division operation 1. Byte by Word - the dividend is in the AX and the divisor is a byte in memory or another register. The operation stores the remainder in the AH and the quotient in the AL. Exercise: Write an assembly language program that will ask the user to enter 2 one-digit numbers(0-9). Your program will then display the sum, difference, product, and quotient of the numbers entered. If the second number is 0, the product and the quotient is automatically zero. Extending values in a register 1. CBW (convert byte to word) - restricted to the use of the AX -automatically propagates the sign bit of the AL(0 or 1) through the AH. Example: AH AL xx 60H CBW 00 60H ;extends AL sign into AH ADD AX,20H 00 80H 2. CWD (convert word to doubleword) - used to extend a 1-word value to a doubleword by duplicating the sign bit of the AX through the DX Example: MOV AX,WORD1 ;move word to AX CWD ;extend word to DX:AX

Processing ASCII Data 1. AAA - ASCII Adjust after Addition -checks the rightmost hex digit (4 bits) of the AL register. If the digit is between A and F or the auxiliary carry flag(AF) is 1, the operation adds 6 to the AL register, adds 1 to the AH register. In all cases, it clears the leftmost hex digit of the AL to zero 8 (38h) + 4 (34H) = 6CH -ignore the leftmost 6, and add 6 to the rightmost hex C = 0102H Example: ADD AL,BL ;Add 34H to 38H, equals 006CH AAA ;Adjust for ASCII Add, equals 0102H OR AX,3030H ;Result is now 3132H 2. AAS - ASCII Adjust after Subtraction -checks the rightmost hex digit (4 bits) of the AL register. If the digit is between A and F or the auxiliary carry(AF) is 1, the operation subtracts 6 to the AL register, subtracts 1 from the AH register. In all cases, it clears the leftmost hex digit of the AL to zero Note: for AAA and AAS - The instructions are coded without operands and automatically adjust an ASCII value in the AX register. - All that is very well for adding 1-byte ASCII numbers. Adding multibyte ASCII numbers, however, requires a loop that processes from right to left 3. AAM - ASCII Adjust after Multiplication Divides the AL by 10 (0A) and stores the quotient in the AH and the remainder in the AL. Example: 5 * 9 = 2D AAM 0405 or 3030h AND CL,0FH ; convert CL to 09h AND AL,0Fh ; convert AL to 05h MUL CL ; multiply AL by CL AAM ; convert AX OR AX,3030H ; convert AX to ASCII 4. AAD - ASCII Adjust Before Division Multiplies the AH by 10 (0AH), adds the product 20 (14H) to the AL, and clears the AH. The divisor can be only a single byte containing 01 to 09. Example: assume that AX contains ASCII value 28 (3238H) and CL is 7 (37H) AND CL,0FH AND AX,0F0FH AAD DIV CL Note: If the divisor is greater than one byte, you have to provide yet another loop to step through the divisor. Swapping values in a register and memory: XCHG Instruction - swaps the two data items Syntax: XCHG register/memory , register/memory

Date and Time Services of Int 21H that can be used to display/change system date or system time Service 2AH Function Get System Date Returns these binary values: AL = day of week (Sunday = 0) CX = year (1980-2099) DH = month (01-12) DL = day (01 31) Set System Date Load these binary values: CX = year (1980-2099) DH = month (01-12) DL = day (01 31) On return, AL indicates a valid (00H) or invalid (FFH) operation Get System Time Returns these binary values: CH = hours, in 24-hour format (00-23, where midnight = 00) CL = minutes (00-59) DH = seconds (00-59) DL = hundredths of a second (00-99) Coding mov ah, 2Ah int 21h

2BH

mov ah,2Bh mov cx, <year> mov dh, <month> mov dl,<day> int 21h

2CH

mov ah,2Ch int 21h

2DH

Set System Time mov ah,2Dh Load these binary values: mov ch, <hour> CH = hours, in 24-hour format (00-23, where midnight = 00) mov cl, <minutes> CL = minutes (00-59) mov dh, <seconds> DH = seconds (00-59) mov dl, <hundredths> DL = hundredths of a second (00-99) int 21h On return, AL indicates a valid (00H) or invalid (FFH) operation Might not work in Windows XP, Windows 2000 and Windows Vista due to user restrictions.

S-ar putea să vă placă și