flat assembler
Message board for the users of flat assembler.

Index > DOS > Newbie here! (HEX vs DEC, text output using DOS, VGA)

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
Hello everyone! I've been skimming through this forum for hours and I finally got the guts to register. So, I took interest in Assembly programming after I becoming bored with Perl. I had plans to learn C but it resembled Perl in a lot of ways so I decided to look to Assembly as it is out of the ordinary for me. I have dabbled around with examples and some things simply are not making sense. Take a look at this code:

Code:
name "hi-world"

org 100h

; set video mode    
mov ax, 3     ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)
int 10h       ; do it!

; cancel blinking and enable all 16 colors:
mov ax, 1003h
mov bx, 0
int 10h

; set segment register:
mov     ax, 0b800h
mov     ds, ax

mov [02h], 'H'

mov [04h], 'e'

mov [06h], 'l'

mov [08h], 'l'

mov [0ah], 'o'

mov [0ch], ','

mov [0eh], 'W'
 
mov [10h], 'o'

mov [12h], 'r'

mov [14h], 'l'

mov [16h], 'd'

mov [18h], '!'

; color all characters:
mov cx, 12  ; number of characters.
mov di, 03h ; start from byte after 'h'

c:  mov [di], 11101100b   ; light red(1100) on yellow(1110)
    add di, 2 ; skip over next ascii code in vga memory.
    loop c

; wait for any key press:
mov ah, 0
int 16h

ret
    


Now can you please help me understand a few things?

what does
Code:
mov ax,3    
actually do?
what does 3 stand for and how is this setting text mode?
I think i am lacking a conversion of the meanings or something.
same with
Code:
mov ax,0b800h    

I do understand mov ds, ax is moving ax value to data segment? to be processes because you cannot process from a register.. i think
can some one please fill me in and correct my overzealous conclusions.

Thanks!!
(A lost ASM wanna be programmer)

Mod notes : moved from Test into DOS by Loco, enhanced subject and reduced duplicate post to 1 piece by DOS386

_________________
-p3rlphr33k-
(Soon to be ASMphr33k)
Post 22 Dec 2009, 06:16
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
mov ax,3 - move dest,source. Moves that number '3' into the register 'ax'. The instruction that comes next (i.e. 'int 10h') is where the work of changing screen modes is done. It call the BIOS (some pre-written code) to make changes. The value in ax tells the BIOS code what you want it to do.

The CPU has registers named ax, bx, cx, dx, si, di, bp and sp in 16bit mode.
Post 22 Dec 2009, 06:27
View user's profile Send private message Visit poster's website Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
Nice! I am familiar with hardware and the that it is placing the value in the register. I just didnt know the the 3 was triggering the bios. So is there a chart of what number do what in the bios? How do you know what numbers do what?

Thanks again!
Post 22 Dec 2009, 06:32
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
Sorry for the newbie questions...
I feel as though I have stepped back 8 years and I am learning to program from the beginning. I have only ever "programmed" in PERL, PHP... the usual web stuff. But assembly has always been in the back of my mind. I am excited to finally program something that matters much more on a machine level. I will be excited to know how to write my own hello world without cheating..hehehe
Post 22 Dec 2009, 06:37
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
Search for Ralf Brown's Interrupt List.
Post 22 Dec 2009, 06:42
View user's profile Send private message Visit poster's website Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
Sorry but... I just dont know how this works..

I looked here: http://www.ctyme.com/intr/int.htm
I see 03, it doesnt say anything about text mode in any of the links provided, and there is not just a '3'.
also looked here: http://en.wikipedia.org/wiki/BIOS_interrupt_call
still no 3.. I am back to being lost

wiki also has 03:
"03h CPU: The lowest non-reserved interrupt, it is used exclusively for debugging, and the INT 03 handler is always implemented by a debugging program"

Any other resources, or can you help me make sense of this?
Post 22 Dec 2009, 07:04
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
i understand that 3 decimal and 03h is hex so are they the same interrupt?
Post 22 Dec 2009, 07:05
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
This what im looking for?

Code:
10h         
-----
Video Services - installed by the BIOS or operating system; called by software programs
AH      Description
00h      Set Video Mode
01h   Set Cursor Shape
02h         Set Cursor Position
03h      Get Cursor Position And Shape
04h    Get Light Pen Position
05h   Set Display Page
06h         Clear/Scroll Screen Up
07h   Clear/Scroll Screen Down
08h         Read Character and Attribute at Cursor
09h   Write Character and Attribute at Cursor
0Ah  Write Character at Cursor
0Bh        Set Border Color
0Eh         Write Character in TTY Mode
0Fh      Get Video Mode
13h   Write String
    
Post 22 Dec 2009, 07:32
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
and more...

http://en.wikipedia.org/wiki/INT_10
found here too!
http://www.ctyme.com/intr/rb-0088.htm

Think this is what i wanted to know! Sorry i keep talking to myself.. Sad

I am really not an idiot i swear all though I feel like it asking newbie questions. I am just not used to this type of programming.
Post 22 Dec 2009, 07:34
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
Thanks for your help revolution! I would stay and get to know more about you but its 2am here and I need to get some rest for work tomorrow. I will be back on later for sure. I look forward to meeting more people on this board Im sure everyone here is great!

Thanks again
Post 22 Dec 2009, 07:50
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
ax=3 means: ah=0 and al=3.

So int 10h with ah=0 is to set the video mode. al=3 tells the BIOS code you want video mode 3 (80x25 text mode)
Post 22 Dec 2009, 08:46
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
p3rlphr33k, I'll move this thread to DOS forum (or perhaps Main), so be ready to find it there (I'll wait some days before doing it or until you reply something here, whatever comes first).
Post 22 Dec 2009, 14:36
View user's profile Send private message Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
whenever your ready locodeassembly Smile
Post 22 Dec 2009, 18:49
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
Round II DING

ok, I understand the ORG tell the compiler that it is a specific file type..
Is there also a chart that shows what each type is?
and what does ORG stand for?

I tried google but its difficult to search for a domain extension lol

"Assebmly language ORG" = "did you mean assemblylanguage.org?"

in one of my example programs i noticed ORG 100h, another was ORG 256, and another didnt have one at all!

Any one care to fill me in?

Thanks Smile

_________________
-p3rlphr33k-
(Soon to be ASMphr33k)
Post 22 Dec 2009, 21:48
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
Quote:
i noticed ORG 100h, another was ORG 256

100h = hexa
256 = decimal
100h = 256 Very Happy
Post 22 Dec 2009, 21:54
View user's profile Send private message Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
why does this work:

Code:
org 256

mov ah,2
mov dl,'A'

int 21h
int 20h
             
    


but this doesnt?

Code:
org 256

mov ah,2
mov dl,'Test print'

int 21h
int 20h
             
    


I know it has some thing to do with moving a single letter rather than a string.. do I need to define a db first?

Code:
org 256

mesg db 'test print'

mov ah,2
mov dl,mesg

int 21h
int 20h
             
    


this doesnt work.. but am i on the right track?
Post 22 Dec 2009, 22:03
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
Teehee wrote:

100h = hexa
256 = decimal
100h = 256 Very Happy


WOW did i over look that, thanks teehee lol

_________________
-p3rlphr33k-
(Soon to be ASMphr33k)
Post 22 Dec 2009, 22:06
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
In DOS function 9 is for printing strings. And the strings are terminated by a $ symbol.
Code:
mov ah,9 ;print string
mov dx,mystring
int 21h
int 20h

mystring: db 'Hello everybody$'    
Post 22 Dec 2009, 22:14
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17475
Location: In your JS exploiting you and your system
revolution
p3rlphr33k: look into the examples folder that comes with the fasm download. It has working examples that you can use to learn from.
Post 22 Dec 2009, 22:15
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
p3rlphr33k wrote:
why does this work:

Code:
mov dl,'A'    


but this doesnt?

Code:
mov dl,'Test print'    


Because DL = 1byte and 'Test print' = 10 bytes Smile
You are trying to move a value greater than register size.

Quote:
I know it has some thing to do with moving a single letter rather than a string.. do I need to define a db first?
Code:
org 256

mesg db 'test print'

mov ah,2
mov dl,mesg

int 21h
int 20h           
    


this doesnt work.. but am i on the right track?


try this:
Code:
org 256

mov ah,2
mov dl,mesg

int 21h
int 20h           

mesg db 'test print$' ; at end... and don't forget '$'
    

_________________
Sorry if bad english.
Post 22 Dec 2009, 22:18
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.