Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Rid of Excess Zeros In Memory Dump

Status
Not open for further replies.

disassembled

Technical User
Feb 26, 2003
2
US
This is a program that is pretty much a memory dump, that asks the user for a segement (i.e. 000A), an address (i.e. 0000), and the number of bytes (i.e. 0016). The output looks like 000A:0000 bytes *ascii* and the next line has 000A:0010 bytes *ascii*, however on the last line of output, it seems to be placing excess zeros between the bytes and the ascii unless of course you choose 20 bytes. How can I get rid of these?



title Memory Dump memorydump.asm

dosseg ; Specifies to use a DOS segment
.286 ; Enables pentium instructions
.model small ; Uses small memory model
.stack 100h ; Identifies Stack Segment at offset 100 Hex

.data
EnterSegment db 'Please Enter the 4 Digit Segment: ','$'
EnterAddress db 'Please Enter the 4 Digit Address: ','$'
EnterNumByte db 'Please Enter the Number of Bytes: ','$'
ReturnString db 0ah, 0dh, '$'
ASCIITable db '0123456789ABCDEF'
Here db 4 dup (' ')
SegmentToUse dw 1 ; Holds segment entered by user
AddressToUse dw 1 ; Holds address entered by user
NumberOfBytes dw 1 ; Holds Number of Bytes to Display
ASCIIString db 48 dup (' '), ' ' ; Holds Mem converted to ASCII String
BeginString db ' ','*' ; Holds Start chars for End String
TextString db 17 dup (' ') ; Holds Valid Text Chars from mem
EndString db '*',0ah,0dh,'$' ; Holds End chars for End String
HoldSegment db 4 dup (' '),':','$'
HoldAddress db 4 dup (' '),' ','$'



.code ; Identifies code segment
main proc
mov ax,@data ; Load address of data into DS Register
mov ds,ax

; Get the segment and convert to 16-bit Integer
mov ah,09 ; Command String Output
mov dx,offset EnterSegment ; Get location of string
int 21h ; Output Segment Request
call Input ; Value returned in AX
mov SegmentToUse,ax ; Save returned value
mov ah,09 ; Command String Output
mov dx,offset ReturnString ; Get Location of Return String
int 21h ; Output Return String

; Get the address and convert to 16-bit Integer
mov ah,09 ; Command String Output
mov dx,offset EnterAddress ; Get location of string
int 21h ; Output Segment Request
call Input ; Value returned in AX
mov AddressToUse,ax ; Save returned value
mov ah,09 ; Command String Output
mov dx,offset ReturnString ; Get Location of Return String
int 21h ; Output Return String


; Get number of bytes and convert to 16-bit Integer
mov ah,09 ; Command String Output
mov dx,offset EnterNumByte ; Get location of string
int 21h ; Output Segment Request
call Input ; Value returned in AX
mov NumberOfBytes,ax ; Save returned value
mov ah,09 ; Command String Output
mov dx,offset ReturnString ; Get Location of Return String
int 21h ; Output Return String
; Output information to screen

mov es,SegmentToUse ; Load the Segment
mov si,AddressToUse ; Load the Address




OutputString:
mov di,offset ASCIIString; Load destination
mov al,' ' ; Load blank


mov ax,si ; Move Address to convert and print
mov al,ah
call ItoA
mov HoldAddress,ah
mov HoldAddress+1,al

mov ax,si
call ItoA ;176
mov HoldAddress+2,ah
mov HoldAddress+3,al

mov cx,48 ; load loop counter


ClearASCIIString: ; Removes all unnecessary characters
mov ds:[di],al ; Blank out the character
inc di ; Point to next location
loop ClearASCIIString
mov di,offset TextString ; Load destination
mov al,' ' ; Load blank
mov cx,16 ; load loop counter


ClearTextString: ; Removes all unnecessary characters
mov ds:[di],al ; Blank out the character
inc di ; Point to next location
loop ClearTextString
mov di,offset ASCIIString; Load destination
mov bp,offset TextString ; Load other destination

; Preparing to place the Ascii information
mov cx,NumberOfBytes
cmp NumberOfBytes,10h
jb Loop3
sub NumberOfBytes,10h
mov cx,10h
jmp Loop1

Loop3:
mov NumberOfBytes,0

Loop1 equ $ ; Checks for a printable character to place in text string
mov al,es:[si] ; Get a byte of memory
inc si ; Point to next byte
mov ds:[bp],' ' ; Place a blank in the text string
cmp al, ' ' ; Check Lower Bound
jb Loop2
cmp al, '}' ; Check Upper Bound
ja Loop2
mov ds:[bp],al ; Place the character in the text string

Loop2: ; Puts the ASCII codes in the main string.
inc bp ; Point to Next Location in the String
call ItoA ; AX will contain characters
mov ds:[di],ah ; Save the High Character
inc di ; Point to Next Location in String
mov ds:[di],al ; Save the Low Character
inc di ; Point to Next Location in String
mov ds:[di],' ' ; Load a blank character
inc di ; Point to Next Location in String
Loop Loop1

; Outputs the string to the screen

mov ax,es ; Move Segment to convert and print
mov al,ah
call ItoA
mov HoldSegment,ah
mov HoldSegment+1,al

mov ax,es
call ItoA
mov HoldSegment+2,ah
mov HoldSegment+3,al
mov ax,0900h
mov dx,offset HoldSegment
int 21h

mov ax,0900h
mov dx,offset HoldAddress
int 21h

mov ah,9 ; Command string output
mov dx,offset ASCIIString; Setup parameter
int 21h ; Command DOS Services
cmp NumberOfBytes,0 ; Continue until end of string
jnz OutputString

mov ax,4C00h ; Terminate Process
int 21h ; Invoke DOS Service
main endp ; End of the main procedure

; Beginning of Input procedure
Input proc
push bx ; Save registers that may be used
push cx
push dx
push si

; Input information from user
mov ah,1 ; Setup for retrieving a character
int 21h ; Call DOS Services
mov Here,al ; Save the 1st character
int 21h ; Call DOS Services
mov Here+1,al ; Save the 2nd character
int 21h ; Call DOS Services
mov Here+2,al ; Save the 3rd character
int 21h ; Call DOS Services
mov Here+3,al ; Save the 4th character


; Convert all the characters
mov bx,4 ; Load Loop Counter
mov si,offset Here ; Get Starting Address of string
xor dx,dx ; Clear dx register
mov cx,12 ; Load shift value

L1:
xor ax,ax ; Clear input register
mov al,[si] ; Get character from string
sub al,'0' ; Convert input to Number
cmp al,0ah ; Check for Alpha characters
jb cont1 ; Jump if numeric
sub al,7 ; Subtract off additional number

CONT1:
shl ax,cl ; Move data to correct position in number
add dx,ax ; Add quantity to Number
sub cl,4 ; Reduce shift count
inc si ; Point to next character
dec bx ; Reduce loop counter
jnz L1 ; Continue until done

; Put data in output register
mov ax,dx

; Restore the registers that were used
pop si
pop dx
pop cx
pop bx
ret
Input endp ; End of Input Procedure

; Beginning of ItoA Procedure

ItoA proc

; Save used registers
push bx
push cx

; Convert the upper nibble into Ascii
push ax ; Save for later
shr al,4 ; Obtain the upper nibble
and ax,0Fh ; Remove all unneeded bits
mov bx,ax ; Put into index register
mov ch,ASCIITable[bx] ; Convert to ASCII

; Convert the lower nibble into Ascii
pop ax ; Retrieve later
and ax,0Fh ; Remove all unneeded bits
mov bx,ax ; Put into index register
mov cl,ASCIITable[bx] ; Convert to ASCII

mov ax,cx ; Transfer to return value

; Restore the used registers
pop cx
pop bx
ret
ItoA endp
end main
 
Nevermind, I've figured it out. You can all disregard this. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top