.MODEL SMALL ; this defines the memory model .STACK 100 ; define a stack segment
ID: 3661203 • Letter: #
Question
.MODEL SMALL ; this defines the memory model .STACK 100 ; define a stack segment of 100 bytes .DATA ; this is the data segment .CODE ; this is the code segment MOV AX,@DATA ; get the address of the data segment MOV DS, AX ; and store it in DS register MOV AH, 0Fh ; get current video mode INT 10h PUSH AX ; save current video mode MOV AH, 00h ; set video mode MOV AL, 12h ; graphics 640x480 INT 10h ; draw a green color pixel at location (320, 240) MOV AH, 0Ch ; Function 0Ch: Write pixel dot MOV AL, 02 ; specify green color MOV CX, 320 ; column 320 MOV DX, 240 ; row 240 MOV BH, 0 ; page 0 INT 10h MOV AH, 07h ; wait for key press to exit program INT 21h POP AX ; retrieve original video mode MOV AH, 00h INT 10h ; restore original video mode MOV AX, 4C00H ; Exit to DOS function INT 21H END ; end of the program But the problem is how to make it draw by "pressing arrows " as it said on the quesiton below ?
Explanation / Answer
ASSEMBLER DIRECTIVES FOR IBM-PC PROGRAMS The following is a discussion of the assembler directives applicable to packages like Microsoft Masm and Turbo Assembler. These packages are used to write machine code programs which run under PCDOS. EQUATES The EQU directive creates absolute symbols and aliases by assigning an expression or value to the declared variable name. Its format is, name EQU expression An absolute symbol represents a 16bit value; an alias is a name that represents another symbol. The declared name must be unique, one that has not been previously declared. pi EQU 3.14159 clearax EQU xor ax,ax The first example directs the assembler to replace every occurrence of the name pi with the value 3.1459, whilst the second example instructs the assembler to replace every occurrence of clearax with the instruction xor ax,ax BYTE STORAGE The DB directive allocates and initializes a byte (8bits) of storage for each argument. Its format is, name DB initialvalue,,, The name portion is optional. value1 DB 16 form DB 6*2 text DB "Enter your name:" In the first example, value1 is assigned a byte, and is initialized to 16, the second example sets form equal to 12 and assigns it a byte, and in the last example, text is defined as a sequence of bytes which each contain a character from the specified string. The first byte will be initialized to 'E', whilst the last byte will be initialized to a space character. WORD STORAGE The DW directive allocates a word (2bytes) of storage for each initialized value. Its format is, name DW initialvalue,,, The name portion is optional. DW ? mess DW 'ab' The first example allocates one word of storage, but does not define its initial value (?). The second example defines mess as a word initialized with the character string 'ab'. Strings when using the DW directive must not contain more than two characters. The 'b' will be placed in the low-order byte, and the 'a' will be placed in the high order byte. If only one character is specified, the high-order byte will contain 00H. The low-order byte appears FIRST for Intel Processors. TITLE The title directive specifies the program listing title. TITLE Graphics This appears at the top of each page in the assembler list file, after the source file name. NAME The name directive is used to set the name of the current module. The module name is used by the linker when displaying error messages. If no module name is used, the linker will use the name specified using the title directive. NAME Calculate_Gross PAGE CONTROL The PAGE directive can be used to designate the line length and width for the program listing; normally used to generate a page break in the assembler listing file. When assembly is taking place, and the page directive is encountered, the assembler generates a form-feed character to set a new page, and continues the assembly on the new page. In this way, the programmer can organize a printout of modules on a per page basis, so that the printout of more than one module per page does not occur. PAGE 66,132 ; 66 lines per page ; 132 characters wide PAGE ; go to new page in list file PROCEDURES These directives are used to implement small procedures (modules). name PROC codetype .... ret name ENDP The last instruction in a procedure is a RETurn instruction. The codetype is FAR for large memory models, NEAR for small memory models. A procedure must be entered using the appropriate CALL instruction. DEFINE DOUBLE WORD, DEFINE QUAD WORD and DEFINE TEN The DD directive defines a double word [4bytes] of storage. This is used to reserve storage for 32 bit integers, floating point numbers, or far pointers to code or data [segment:offset pair]. The DQ directive defines a quad word [8bytes] of storage for double precision floating point numbers. The DT directive defines 10bytes of storage. This is normally used for Packed BCD numbers and a 10 byte temporary real floating point value, as this storage format is also used by the 80x87 arithmetic co-processor. OFFSET The offset directive returns the number of bytes a variable begins at, relative to the start of the segment it is in. This is necessary when calling PCDOS routines. .DATA temp db 10 mess db 'Hi there','$' .CODE start: mov ax, @data mov ds, ax mov ah, 9h mov dx, OFFSET mess ;1 byte in .DATA segment int 21h ;print message mov ax, 4c00h ;return to PCDOS int 21h END start SAMPLE PROGRAM FOR IBM-PC TITLE Doscall ;Doscall.asm source file .MODEL SMALL CR equ 0ah LF equ 0dh EOSTR equ '$' .stack 200h .datamessage db 'Hello and welcome.' db CR, LF, EOSTR .code print proc near mov ah,9h ;PCDOS print function int 21h ret print endp start: mov ax, @data mov ds, ax mov dx, offset message call print mov ax, 4c00h int 21h end start The program is assembled by typing $ TASM DOSCALL Turbo Assembler V1.0 Copyright(c)1988 by Borland International Assembling file: DOSCALL.ASM Error messages: None Warning messages: None Remaining memory: 257k $ This produces an object file named DOSCALL.OBJ which must be linked to create an executable file which can run under PCDOS. $ TLINK DOSCALL Turbo LinkV2.0 Copyright (c) 1987, 1988 Borland International $ The program when run, produces the following output. $ DOSCALL Hello and welcome. $
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.