Assembly Source series of Showmem

Source: Internet
Author: User
Tags exit command line count reset utext

This is the past DOS era of the compilation of source code, although has passed, but for the study of the assembly is still helpful, assembly language is just a basic programmer language, most people can grasp, not necessarily in-depth research.

;************************************************************************
;*
; * SHOWMEM (C) 1997 Ronsoft. *
;*                                   *
; * A little utility thats shows what ' s in A given mem position. *
; * Usage: *
; * Showmem <segment,offset/startaddress> *
; * Where segment and offset are bit hexadecimal values or *
; * A single bit value. *
; * Just like this: *
; * Showmem 00000000 or Showmem 0. *
;*                                   *
; * Ronald Nordberg. *
; * Silverv 刧 en 3 *
* 907, Ume? *
; * Sweden *
; * christine.martinson@swipnet.se *
; * http://home2.swipnet.se/~w-20064 *
;*                                   *
; * This are all public DOMAIN freeware. *
; * Let EM KNOW IF i CODE. *
;*                                   *
;************************************************************************
; some euqates for readability
KBD equ 16h; keyboard IRQ
Msdos equ 21h; MSDOS IRQ
Reset equ 0DH;d ISK Reset
Dfopen equ 0fh; open Disk File
Dfclose equ 10h; close Disk File
SEARCHF equ 11h; search
Searchn equ 12h; Search Next
Seqread equ 14h; sequential disk read
Seqwrite equ 15h; "" Write
SETDTA equ 1ah; Set disk transfer area address
Createf equ 3ch; create file with handle
OPENF equ 3DH; open file with handle
Closef equ 3eh; close file with handle
READF equ 3fh; read from file with handle
Writef equ 40h; write to file with handle
SETFP equ 42h; set file pointer
AllocMem equ 48h; Allocate memory
Freemem equ 49h; free memory
Changebs equ 4ah; change block size
FindFirst equ 4eh;
Exit equ 4c00h; Msdos exit
[BITS 16]; NASM Stuff
[ORG 0x100]
S1:
mov ax,cs; Get code segment
MOV ds,ax;
mov [Comseg],ds; save it there
mov si,0080h;D OS command line page 0
LODSB load size of command line
CMP al,0 anything on command?
Jbe usage noo, show usage
CBW extend AL to AX
Xchg bx,ax swap size to BX for indexing
mov byte [bx+si],0; null terminate command line
Call Parse;p arse command line
JMP main; go in with main
Usage:mov bx,utext;p ointer usage text
JMP Errout; Skip this
Main
MOV si,inbuff check for valid HEX input
MOV bx,errt1;p roper text
ISHEX:LODSB get the Char
CMP al, ' 0 '
JB Errout
Force uppercase with AL,0DFH;
CMP al, ' F '; >f?
JA errout; yeahh, dump this
Loop Ishex
Call Hexbin, make Hex bin
; start address now in EDX
MOV ax,dx; get low word (segment)
mov es,ax; start segment
SHR edx,16 shift in offset
mov di,dx; start offset
Dopage:
Push es; Save registers
Push di
Push DS
Push SI
MOV ax,es
mov Ds,ax make ds=es
mov si,di; si=di
    
Call ShowPage, show it
    
Pop si; restore registers
Pop ds
Pop di
Pop es
Add di,512 Adjust Memory position
; Xor Ah,ah;
; int KBD
    
MOV bx,text;
Call Write
mov ah,0 wanna the next screen?
int kbd; Chek out keyboard buffer
Force UPPER case with AL,0DFH;
CMP al, "Q"; Wanna quit?
Je quit; yeahh
JMP dopage
Errout:
Call Write
Quit
MOV ax,exit
int Msdos
;***********************************************************
; * Convert ASCII hex to bit binary
; * Input = command line buffer, output EDX
;***********************************************************
Hexbin:
mov si,inbuff;p ointer command line buffer
XOR Edx,edx Clear binary output
Aschexbin:
Lodsb
CMP al, ' 0 ';< 0
JB NOTASC; Yes invalid character
CMP al, ' 9 '; <= 9
Jbe Astrip Yes, strip high 4 bits
Force upper case with AL,05FH;
CMP al, ' a ';< ASCII a
JB NOTASC Yes, invalid character
CMP al, ' F ';> ASCII F
JA notasc Yes, invalid character
Add al,9 OK, add 9 for strip
Astrip:
and AL,0FH strip high 4 bits
MOV cx,4 set shift count
SHL edx,cl rotate edx 4 bits
XOR Ah,ah Zero out AH
Cbw
Add edx,eax add digit to value
JMP Aschexbin; continue
Notasc:ret
;*********************************************************************
; * Format and show the stuff in a "sector"
; * Input SI
;*********************************************************************
ShowPage:
mov cx,32; 32*16=512
Arow:push CX
mov di,outline; output buffer
mov cx,16;p rocess bytes
Hexrow:push CX
LODSB load Al with byte
mov dl,al; get value
MOV cx,2 2 nibbles
Chexb:push CX; save that
MOV cl,4 4 bits
Rol dl,cl Rotate Source left
mov al,dl move digit into AL
and al,15 Clear High nibble
DAA Adjust AL if A through F
Add al,240 Bump the Carry
ADC al,40h convert HEX to ASCII
STOSB Copy to Buffer
Pop cx; get digit counter
Loop Chexb next digit
mov al,32 copy a space
Stosb
Pop cx; restore loop counter
Loop hexrow; Loop on
mov al,32 copy 2 spaces
Stosb
Stosb
Sub si,16; Adjust source back
mov cx,16 copy ASCII bytes
Cccp:lodsb
CMP al,32;< space?
JB Noa; Yeahh, skip it
STOSB no, store in buffer
JMP Next
Noa:mov al, '. '
Stosb
Next Loop CCCP
MOV al,13
Stosb
MOV al,10
Stosb
MOV al,0; null terminate line
Stosb
MOV bx,outline;
Call Write
Pop CX
CMP cx,17
Jne Nopause
Push DS
MOV Ax,cs
MOV Ds,ax
MOV bx,text1
Call Write
Pop ds
XOR Ah,ah
int KBD
Nopause:
Loop Arow Next bytes
Ret
;************************************************************************'
; * Convert bin WORD to HEX ASCII. Input DX. result in Numbuff *
;************************************************************************
Binhex:pusha
MOV di,numbuff;d estination buffer
mov Dx,[count]; binary number
MOV cx,4; four nibbles
Convhex:
Push CX; Save counter
MOV cl, 4; 4 bits
Rol DX, cl; rotate source Left
mov al, DL; move Digit into AL
And al, clear high nibble
DAA Adjust AL if A through F
Add Al, Bump the Carry
ADC al, 40h; convert HEX to ASCII
STOSB Copy to Buffer
Pop cx; get digit counter
Loop Convhex next digit
mov al,32 copy a space
Stosb
MOV al,0; null terminate
Stosb
Popa
Ret
;*************************************************************************
* Writes out of the NULL terminated text supplied in BX. *
; * or writes out DATA,BX and SIZE,CX if called at Lwrite. *
;*************************************************************************
Write:pusha
mov si,bx; Copy to Si
MOV cx,0 clear Count
WLOOP:LODSB load AL with SI
CMP al,0 end of line?
Je lwrite; yeahh
Inc CX; No, incrase byte count
JMP wloop; test next byte
Lwrite:mov dx,bx text address in DX
MOV bx,1 filehandle standard output = 1
MOV Ah,writef; MS-DOS WriteFile with handle is 040
int msdos; write buffer to standard output
Popa
RET;d One
;*************************************************************************
; * My Kind the command line parsing. It just checks if there 飐
; * Any blankspaces between the options. The parameters ends up
; * In the Inbuff separated by 0:s, binary zeroes.
;*************************************************************************
Parse
mov Di,inbuff; our buffer
IFSPC:CMP Byte [si],32; leading space?
Jne NOSPC; noo
Inc si; yeahh, dump that
JMP IFSPC Check Next
Nospc:mov cx,1 were, so we got one arg
COPY1:LODSB load byte SI to AL
CMP al,0 0? (End of line)
Je done; yeahh
CMP al,32; Space?
Je cop2; yeah
STOSB Noo, move AL to Di, incrase di
JMP copy1.
Cop2:mov byte [di],0; null terminate
Add cx,1
Inc di;d UMP that byte
JMP copy1;
Done:mov byte [di],0; null terminate
a ret;
; *************************** DATA STUFF **********************************
Xms_segment DW 0
Xms_offset DW 0
Inbuff times, DW 0; 128 byte command line buffer
Outline times DW 0, buffer output line
Numbuff times 7 DW 0; Word ASCII number buffer
COMSEG DW 0
Count DW 0
Bcount DW 0
Acount DW 0
; outbuff Times 0 db
Utext db ' Showmem (C) 1997 Ronsoft. ', 13,10
DB ' Usage:showmem [start address]. ', 13,10
DB ' Start address = hexadecimal. ', 13,10,0
Text:db 13,10, ' Q = Quit. Any key = Next page. ', 13,10,0
Text1:db 13,10, ' any Key = Next 256 Bytes. ', 13,10,0
Errt1:db ' that's not hexadecimal. ', 13,10,0
S2:
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.