WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
What is FASM G
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
Forum Rules Snippets forum rules

In this forum all the registered users may post their snippets of code they whish to share with the WinAsm Studio community following these basic rules:
* Only snippets of code are accepted in the topics of this forum.
* Discussions, suggestions, requests etc. must be posted in the "Discussions" topic.
* Do not post copyrighted material.
Administrators/moderators may edit, move or delete the entries that do not follow the preceding rules.

 

Tracing register contents, have you gone crazy trying to trace register contents? It happens when writing assembly programs.

te987
Quote Post


New Member
*

Group: Members
Posts: 11
Member No.: 2876
Joined: 30-August 06


::/ \::::::.
:/___\:::::::.
/| \::::::::.
:| _/\:::::::::.
:| _|\ \::::::::::.
:::\_____\:::::::::::................................ASSEMBLY.TECHNIQUES

80x86 Register Equates
by te987
te987@hotmail.com

Have you ever had to debug a program where most of the data was
contained in registers? (As it should be in a good assembly program.)
Have you gone crazy trying to trace register usage? (Yeah, I know that
being crazy helps when writing assembly programs!) The following
technique makes tracing register usage easy...

Simply create an equate for each register. Place the equates in an
include file and "include register.inc" at the top of every file.

Now, assemble your program using the following Turbo Assembler
command line:

tasm /l/c somefile

The /l switch instructs TASM to generate a listing, and the /c says
to create a cross reference.

(An aside: I also use MASM 6.xx, but have never been able to find
the correct switch(es) in either MASM.EXE or ML.EXE to make it
generate a cross reference. "masm /l/c somefile" generates a symbol
table, but it doesn't give the LINE NUMBERS where the symbol is used.
Most useless... If anyone knows how to do so, I would appreciate
hearing from you...)

The following three files show how to use register equates. First,
the include file:

;====== start of register.inc ================================
CODE
;============================================================================
; File:         REGISTER.INC
;
; Description:  Register symbolic constants.
;============================================================================

ifndef __INCLUDE_REGISTER__
__INCLUDE_REGISTER__    equ     1
_ax     equ     <ax>
_bx     equ     <bx>
_cx     equ     <cx>
_dx     equ     <dx>
_ah     equ     <ah>
_bh     equ     <bh>
_ch     equ     <ch>
_dh     equ     <dh>
_al     equ     <al>
_bl     equ     <bl>
_cl     equ     <cl>
_dl     equ     <dl>
_si     equ     <si>
_di     equ     <di>
_sp     equ     <sp>
_bp     equ     <bp>
_cs     equ     <cs>
_ds     equ     <ds>
_es     equ     <es>
_ss     equ     <ss>
_eax    equ     <eax>
_ebx    equ     <ebx>
_ecx    equ     <ecx>
_edx    equ     <edx>
_esi    equ     <esi>
_edi    equ     <edi>
_esp    equ     <esp>
_ebp    equ     <ebp>
_fs     equ     <fs>
_gs     equ     <gs>
endif;ifndef __INCLUDE_REGISTER__

;====== end of register.inc ================================

Next, a "Hello, world!" program showing equated registers. The first
four lines are TASM directives controlling how the listing is created.
I normally run the == line (and comments) out to column 96. This
prints the full page width in portrait when using 16.67 characters per
inch.

;====== start of hello.asm =================================
CODE
%TITLE "Everyone's first program---""Hello, world!"""
%NOINCL
%CREFREF
%TRUNC
;==================================================
; Description:  Display "Hello, world!".
;               Sample program showing register equates.
;==================================================

       .model  small
       .stack  100h

include register.inc

;==================================================
       .data

hello           db      "Hello, world!",0Dh,0Ah,'$'

;==================================================
      .code

main            proc
       mov     _ax,@data            ;initialize segment registers
       mov     _ds,_ax
       mov     _es,_ax

       mov     _ah,9                ;DOS display string
       mov     _dx,OFFSET hello
       int     21h

       mov     _ax,4C00h            ;exit program with errorlevel 0
       int     21h
main            endp
end     main

;====== end of hello.asm =================================

Finally, the (edited) listing file. Editing consisted of deleting
extra blank lines, form feeds, and narrowing column widths so that the
listing was 72 columns wide (in particular, comments were truncated).

Notice in the symbol table that registers are cross referenced,
with, for example, register _ax being defined at line 10 (in the include
file) and used at lines 20, 21, 22, and 28. Imagine how useful a cross
reference would be if a register was used 200 times!

;====== start of hello.lst ==================================
CODE
Turbo Assembler  Version 4.0        99/99/99 99:99:99       Page 1
HELLO.ASM
Everyone's first program---"Hello, world!"

1              ;==========================================
2              ; Description:  Display "Hello, world!".
3              ;               Sample program showing register equat
4              ;==========================================
5
6 0000                    .model  small
7 0000                    .stack  100h
8
9                 include register.inc
10
11              ;==========================================
12 0000                    .data
13
14 0000  48 65 6C+ hello           db      "Hello, world!",0Dh,0Ah,'$'
15
16              ;==========================================
17 0010                    .code
18
19 0000            main    proc
20 0000  B8 0000s          mov     _ax,@data            ;initialize s
21 0003  8E D8             mov     _ds,_ax
22 0005  8E C0             mov     _es,_ax
23
24 0007  B4 09             mov     _ah,9                ;DOS display
25 0009  BA 0000r          mov     _dx,OFFSET hello
26 000C  CD 21             int     21h
27
28 000E  B8 4C00           mov     _ax,4C00h            ;exit program
29 0011  CD 21             int     21h
30 0013            main    endp
31                 end     main
Turbo Assembler         Version 4.0        99/99/99 99:99:99       Page 2
Symbol Table
Everyone's first program---"Hello, world!"

Symbol Name             Type   Value                       Cref (defined at #)

@CODE                   Text   _TEXT                       #6  #6  #17
@CURSEG                 Text   _TEXT                       #12  #17
@DATA                   Text   DGROUP                      #6  20
@WORDSIZE               Text   2                           #12  #17
HELLO                   Byte   DGROUP:0000                 #14  25
MAIN                    Near   _TEXT:0000                  #19  31
_AH                     Text   ah                          #10  24
_AX                     Text   ax                          #10  20  21  22  28
_DS                     Text   ds                          #10  21
_DX                     Text   dx                          #10  25
_ES                     Text   es                          #10  22

Groups & Segments       Bit Size Align  Combine Class      Cref (defined at #)

DGROUP                  Group                              #6  6  20
 STACK                 16  0100 Para   Stack   STACK      #7
 _DATA                 16  0010 Word   Public  DATA       #6  #12
_TEXT                   16  0013 Word   Public  CODE       #6  6  #17  17

;====== end of hello.lst ==================================

I hope this technique helps. I've been using it for years, having
first learned it in an IBM 360 mainframe environment in college.

Sponsored Links
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topic

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google