First, thanks SO MUCH to hutch, Thomas, and especially NaN for helping get over the crux of starting with assembly. I have written my first original assembly program!
Okay, by original I don't mean it's the first time the world has ever seen this--it just prints an ASCII chart. I mean original in that I wrote all the code myself rather than modifying a tutorial. Anyway, it's pretty trivial, about 50 lines of code, but still, I'm rather pleased. :)
Comments? Thoughts? How could I make this better, smaller, faster, more compact, more readable, etc?
I'm especially concerned about the mul instruction commented out below. Masm claims that the comma is a syntax error. What's up with that?
Thank you all in advance for comments. Code attached below, sorry for it making this post so large.
-Chalain
"We all begin life naked, covered in blood and screaming. But if we live right, it doesn't have to stop there." -- Robert A. Heinlein
Okay, by original I don't mean it's the first time the world has ever seen this--it just prints an ASCII chart. I mean original in that I wrote all the code myself rather than modifying a tutorial. Anyway, it's pretty trivial, about 50 lines of code, but still, I'm rather pleased. :)
Comments? Thoughts? How could I make this better, smaller, faster, more compact, more readable, etc?
I'm especially concerned about the mul instruction commented out below. Masm claims that the comma is a syntax error. What's up with that?
Thank you all in advance for comments. Code attached below, sorry for it making this post so large.
-Chalain
"We all begin life naked, covered in blood and screaming. But if we live right, it doesn't have to stop there." -- Robert A. Heinlein
;=======================================================================
; File: ascii.asm
; Desc: Prints the ASCII chart as a 16x16 grid with hex labels. My
; first (original) assembly program.
; Auth: Chalain
; Date: 04/17/2002
;-----------------------------------------------------------------------
; Notes:
; Win32 Assembly *console* project. To compile and link with masm32,
; use BLDALLC.BAT, or compile by hand like so:
;
; ml /c /coff ascii.asm
; link /SUBSYSTEM:CONSOLE ascii.obj
;
;=======================================================================
;-----------------------------------------------------------------------
; DIRECTIVES
;-----------------------------------------------------------------------
.386
.model flat, stdcall
option casemap:none
;-----------------------------------------------------------------------
; INCLUDES
;-----------------------------------------------------------------------
include \masm32\include\Windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
;-----------------------------------------------------------------------
; .DATA
;-----------------------------------------------------------------------
.data
; ascii-art caption text
AsciiArtTopBar db " ",218, 33 dup(196),191,13,10,0
AsciiArtTopCaption db " ",179
db " 0 1 2 3 4 5 6 7 8 9 A B C D E F "
db 179, 13, 10, 0
AsciiArtTopBar2 db 218,196,197, 33 dup(196),180,13,10,0
AsciiArtBottomBar db 192,196,193, 33 dup(196), 217, 13, 10, 0
AsciiArtVert db 179
ColumnFormat db "%c%X%c ",0 ; formats row headers
CharFormat db "%c ",0 ; formats the actual chars
EndColumnText db 179,13,10,0 ; | + cr + lf
;----------------------------------------------------------------------
; .DATA?
;----------------------------------------------------------------------
.data?
x dd ?
y dd ?
Ascii dd ?
Buffer db 10 dup(?)
;----------------------------------------------------------------------
; .CODE
;----------------------------------------------------------------------
.code
start:
invoke StdOut, addr AsciiArtTopBar
invoke StdOut, addr AsciiArtTopCaption
invoke StdOut, addr AsciiArtTopBar2
mov y,0
.WHILE y<16
mov x,0
invoke wsprintf, addr Buffer, addr ColumnFormat, \
dword ptr AsciiArtVert, y, dword ptr AsciiArtVert
invoke StdOut, addr Buffer
.WHILE x<16
mov eax, y
; mul eax, 16 ; WTF? This is a syntax error?
shl eax, 4 ; shl is probably faster anyway
add eax, x
mov Ascii, eax
; Don't print Ascii 0, 7-10 or 13--they'll trash our output
.IF Ascii == 0 || ( Ascii >= 7 && Ascii <= 10 ) || Ascii == 13
mov Ascii, 20h
.ENDIF
invoke wsprintf, addr Buffer, addr CharFormat, \
dword ptr Ascii
invoke StdOut, addr Buffer
inc x
.ENDW
invoke StdOut, addr EndColumnText
inc y
.ENDW
invoke StdOut, addr AsciiArtBottomBar
invoke ExitProcess, 0
end start