Download presentation
Presentation is loading. Please wait.
1
By Nasser Halasa Assembly Language
2
Directives pseudo-operations
PTR- is a pointer that helps the compiler to define the size of data to store in the memory BYTE PTR indicates the size of 8 bit data MOV BYTE PTR[AX],10H WORD PTR indicates the size of 16 bit data MOV WORD PTR[DI],10H OFFSET – loads a register with the offset address of a memory location NOT the contents of the memory. MOV BX,DATAS; Copy the contents MOV BX,OFFSET DATAS; Copy the offset address
3
Defining Storage Space in memory
DB – Define BYTE DW – Define WORD DD – Define Double ? – Reserve a memory space for data to be used in the future it place zero in to the location specified by ? SEGMENT- define a memory segment contains various forms of data Format Segment Name SEGMENT //Statements Segment Name ENDS
4
ASSUME - to assign a segment to specific segment name
stack_seg segment [ DW 100H DUP(?) ???? ] stack_seg ends Data_seg segment // data go's here Data_seg ENDS Assume SS: stack_seg, DS:DATA_SEG
5
DUP – duplicate Creates an array.
SAM 10 DUP(?) reserve 10 locations of memory for array SAM and stores Zero in each of them Array1 10 DUP(2) reserve 10 locations of memory for array1 and initialize them to 02H EQU – Equate, equates a number ,ASCII, or a label to another label TEN EQU 10 ALPHA EQU 19 ORG – original, the starting address for code or data. It changes the starting offset address of the data in the data segment
6
PROC and ENDP – procedures or subroutines format
Label name PROC {FAR, NEAR} FAR procedure is a global procedure that may reside at any location in the memory system NEAR procedure is a local procedure that is reside in the same code segment as the program ENDP indicates the end of the procedure ADDPRO PROC FAR ADDPRO ENDP RET – return, returns to the main program from a procedure.
7
Memory Organization .Models – specifies the size of memory needed for a program. There are many models mostly we will use TINY model – all data and software fit into 64K-byte memory segment. It is good for small programs SMALL model – one data segment and one code segment, for a total of 128k bytes of memory .EXIT – return to DOS
8
Dos Int21H for in/out put
10
In out single char Function 01 – inputting a single character, with an echo AH = 01 ; function number After the interrupt AL = ASCII code of the input and is echoed to the monitor Function 02 – outputting a single character to the monitor AH = 02 ; function number DL = ASCII code of the character to be displayed
11
String output Function 09 – outputting a string of data to the monitor
AH = 09 ; function number DX = offset address of the ASCII data to be displayed, data segment is assumed The ASCII string must end with the dollar sign $
12
String input Function 0A – inputting a string of data from the keyboard AH = 0A ; function number DX = offset address at which the string of data is stored (buffer area), data segment is assumed and the string must end with <RETURN> After execution: DS:DX = buffer size in bytes (up to 255 char) DS:DX+1 = number of entered characters excluding the return key DS:DX+2 = first character input · · · DS:DX+n = last character input To set a buffer, use the following in the data segment: Buffer DB 10, ? , 10 DUP(FF)
13
First program using segments
Write a program that can reads a key and displays it. key must ends the program CODE_SEG SEGMENT 'CODE' ASSUME CS:CODE_SEG MAIN PROC FAR MOV AH,6 ;READ KEY MOV DL,0FFh INT 21h JE MAIN ;IF NO KEY CMP ;TEST JE MAIN1 ;IF THERE MOV AH,6 ;DISPLAY KEY MOV DL,AL INT 21H JMP MAIN MAIN1: MOV AH,4CH ;EXIT TO DOS MAIN ENDP CODE_SEG ENDS RUN
14
Same program using model
.MODEL TINY .CODE .STARTUP MAIN: MOV AH,6 ;READ KEY MOV DL,0FFh INT 21h JE MAIN ;IF NO KEY CMP ;TEST JE MAIN1 ;IF THERE MOV AH,6 ;DISPLAY KEY MOV DL,AL INT 21H JMP MAIN ;REPEAT MAIN1: MOV AH,4CH ;EXIT TO DOS END RUN
15
Write a program that can read a string and print it out using segments
my_data SEGMENT Assume DS:my_Data org 100H buffer EQU maxsize maxsize db 21H actsize db ? string db 21H dup(?) my_data ends my_program SEGMENT ASSUME CS:my_program mov ah,0aH lea dx, buffer int 21h mov bl, actsize mov bh,0 mov string[bx],'$‘ ; end Input string mov ah,2 mov dl,13 int 21H mov dl,10 mov ah,9 lea dx,string my_program ends RUN
16
RUN Using Modules org 100H .model tainy .data buffer EQU maxsize
maxsize db 21H actsize db ? string db 21H dup(?) mov ah,2 mov dl,13 int 21H mov dl,10 mov ah,9 lea dx,string .exit end .code .startup mov ah,0aH lea dx, buffer int 21h mov bl, actsize mov bh,0 mov string[bx],'$' ;end input RUN
17
Beep Using DOS 21 org 100H .model tainy .code .startup mov cx,10H l1: mov ah,2 mov dl,7 int 21H loop l1 .exit end RUN
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.