Reputation: 13
sorry , I'm a beginner to assembly , so I got an error when i try to jump in TASM , I wanted to set color of these pixels to blue , but i got these errors , please help me so this is my code:
data_here segment
px dw 0
py dw 0
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
;mov ax, data_here
;mov ds, ax
;mov es, ax
assume ds:data_here
;80x*60y 640*480
mov ax,012h
int 10h
ppos1:
mov al, 1
mov cx, px
mov dx, py
mov ah, 0ch
int 10h
inc px
cmp px,59
jne ppos1
inc py
cmp py,5
jne ppos1
mov ah,7
int 21h
int 20h
ends
end start
and this is TASM result:
-------------
12/20/2017 12:27:35 AM : Assembling file - C:\cxcc.asm
12/20/2017 12:27:37 AM : Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International
12/20/2017 12:27:37 AM :
12/20/2017 12:27:37 AM : Assembling file: cxcc.asm
12/20/2017 12:27:37 AM : *Warning* cxcc.asm(7) Reserved word used as symbol: STACK
12/20/2017 12:27:37 AM : **Error** cxcc.asm(32) Near jump or call to different CS
12/20/2017 12:27:37 AM : **Error** cxcc.asm(35) Near jump or call to different CS
12/20/2017 12:27:37 AM : Error messages: 2
12/20/2017 12:27:37 AM : Warning messages: 1
12/20/2017 12:27:37 AM : Passes: 1
12/20/2017 12:27:37 AM : Remaining memory: 468k
12/20/2017 12:27:37 AM :
thanks for help.thanks for help.
Upvotes: 1
Views: 718
Reputation: 16596
Fully fixed code of yours (with some guessing, what did you want), and somewhat more extensive use of directives, read from http://www.ousob.com/ng/masm/ng3e51c.php (I have somewhere also original TASM books which were in package, but no idea where they did end, probably in some box inside some bigger box, placed very close to the previous millennium... need to call archaeologists probably)
.MODEL SMALL
data_here SEGMENT USE16 PAGE MEMORY
px dw 0
py dw 0
ENDS
my_stack SEGMENT USE16 PAGE STACK
dw 128 dup(0)
ENDS
my_code SEGMENT USE16 PARA PUBLIC
ASSUME cs:my_code, ss:my_stack
start:
; set segment registers:
mov ax, data_here
mov ds, ax
ASSUME ds:data_here
;80x*60y 640*480
mov ax,012h
int 10h
xor bh,bh ; page number for pixel write = 0
ppos1:
mov ax, 0C01h ; ah = 0C (write pixel), al = 1 (blue color)
mov cx, [px]
mov dx, [py]
int 10h
inc word ptr [px]
cmp word ptr [px],59
jne ppos1
mov word ptr [px],0
inc word ptr [py]
cmp word ptr [py],5
jne ppos1
; wait for console input without echo
mov ah,7
int 21h
; restore text mode
mov ax,3
int 10h
; terminate EXE through int 21,4C (int 20h works for COM files)
mov ah,4Ch
int 21h
ENDS
END start
And how would my version look - avoiding extremely slow BIOS write pixel, and using 80386 instructions (32b registers):
(dosbox 0.74
which I'm using as DOS emulator supports CPU up to 80586 (Pentium), and 386 emulation is very very solid, 486 is fine too AFAIK, 586 is more experimental ... now I'm not sure, if there's not a glimpse of "686" ("core duo" was it? Intel didn't use "686" any more as numbers can't be registered as (tm), pity, the number scheme was much more clear than current four generations of "i7" CPU on market, not being sure which is latest without research), but I think it's far from working, if it's there)
.MODEL SMALL
data_here SEGMENT USE16 PAGE MEMORY
ENDS
my_stack SEGMENT USE16 PAGE STACK
dw 1024 dup(0)
ENDS
my_code SEGMENT USE16 PARA PUBLIC
.386
ASSUME cs:my_code, ss:my_stack
start:
; init environment
mov ax, data_here
mov ds, ax
ASSUME ds:data_here
mov ax,0A000h
mov es,ax ; es = VRAM segment for direct VRAM writes
;640x480 16 colour mode
mov ax,012h
int 10h
; draw 59x5 rectangle [0, 0] -> [58, 4] with blue color (1)
mov dx,03C4h ; dx = VGA control index register
mov ax,0102h ; INDEX = MASK MAP, MASK = 0x01 (blue bitplane)
out dx,ax ; other planes are zeroed by mode change
; so I will modify only blue bitplane
xor di,di ; initial address to write
mov dx,5 ; number of lines to fill
mov eax,0FFFFFFFFh ; fill value with pixel bits (all set)
fill_line:
; 59 pixels = 7 full bytes (8 bits), and 3 bits in last 8th byte
stosd ; 4 bytes written
stosw ; 6 bytes written
stosb ; 7 bytes written
; patch remaining 3 bits (3 pixels) of 8th byte
mov bl,es:[di] ; read VRAM
or bl,0E0h ; set top 3 bits of old value
mov es:[di],bl ; write it back to VRAM
; actually mov byte ptr es:[di],0E0h would work too, because clear screen
; but this is also showing how set bit to 1 works with OR
add di,640/8-7 ; advance DI to next line
dec dx
jnz fill_line
; wait for console input without echo
mov ah,7
int 21h
; restore text mode
mov ax,3
int 10h
; terminate EXE through int 21,4C (int 20h works for COM files)
mov ah,4Ch
int 21h
ENDS
END start
Tested with TASM 4.1 and TLINK 7.1.30.1 in DOSBOX 0.74, like:
C:\>TASM TEST_EXE
... TASM output ...
C:\>TLINK TEST_EXE
... TLINK output (just version + copyright)
C:\>TEXT_EXE.EXE
.. switches to gfx mode and draws small blue rectangle, waits for some key, exits to DOS (restoring text mode)...
The VGA 12h mode VRAM access knowledge (how to set blue bitplane) taken from http://www.wagemakers.be/english/doc/vga (not sure about total quality of that article, I basically knew exactly what I was looking for (just the VGA control port number + which bit is mask), still recalling how the 16 colour modes VRAM is organized and what I need to write there, so I didn't read the whole article.
Upvotes: 1