; vi:ts=8:sw=8: ; Memory Dumper ; Interactive memory viewer. ; version 0.1 ; ; Features: ; - All dump functionality written. Code cleanup (deleting unused functions) ; might be needed. ; - Still missing "interactive" part. :) ; ; Changelog: ; 2006-04-11 - version 0.1 done. dump_line written and working. start_address: equ 01000h ;Special ASCII characters: LF: equ 0Ah FF: equ 0Ch CR: equ 0Dh org start_address start_address_label: mov SP,0 mov AB,teste call dump_line mov CD,teste mov AB,1234h call print_hex_word mov AB,": " out B out A mov AB,1234h call print_hex_two_bytes mov AB,": " out B out A mov [contador],18 loop1: mov B,[CD] push CD call print_hex_byte pop CD inc CD dec [contador] jnz loop1 halt contador: res 1 teste: db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 ;0000040: 2023 2323 2323 230a 2320 2020 2320 2323 ######.# # ## ;procedure print_hex_byte {{{ ;This procedure prints an 8-bit number in hexadecimal. ;The number is passed on B. print_hex_byte: ;This procedure should be CALLed, and not JuMPed mov C,"0" ;Store the ASCII code for "0" mov D,"A"-"9"-1 mov A,B ;Copy B to A ;print_first_nibble: shr B shr B shr B shr B cmp B,10 jc print_hex_byte_1 ; if( B<10 ) add B,D print_hex_byte_1: add B,C out B ;print_second_nibble: and A,0Fh cmp A,10 jc print_hex_byte_2 ; if( A<10 ) add A,D print_hex_byte_2: add A,C out A ret ;end procedure print_hex_byte }}} ;procedure print_hex_word {{{ ;This procedure prints a 16-bit number in hexadecimal. ;The number is passed on AB. print_hex_word: ;This procedure should be CALLed, and not JuMPed mov C,"0" ;Store the ASCII code for "0" ;print_first_nibble: mov D,A ;Copy A to D shr A shr A shr A shr A cmp A,10 jc print_hex_word_1 add A,"A"-"9"-1 print_hex_word_1: add A,C out A ;print_second_nibble: mov A,D mov D,"A"-"9"-1 and A,0Fh cmp A,10 jc print_hex_word_2 add A,D print_hex_word_2: add A,C out A ;print_third_nibble: mov A,B ;Copy B to A shr B shr B shr B shr B cmp B,10 jc print_hex_word_3 add B,D print_hex_word_3: add B,C out B ;print_fourth_nibble: and A,0Fh cmp A,10 jc print_hex_word_4 add A,D print_hex_word_4: add A,C out A ret ;end procedure print_hex_word }}} ;procedure print_hex_word - does not work {{{ ;This procedure prints a 16-bit number in hexadecimal. ;The number is passed on AB. ;print_hex_word: ;This procedure should be CALLed, and not JuMPed ; mov C,4 ;print_hex_word_loop: ; rl AB ;This does not work, because: ; rl AB ; Carry < AB (16 bits) < Carry ; rl AB ;So, it is like working with a 17-bit value. ; rl AB ; ; mov D,B ;Save B for later use ; and B,0Fh ; cmp B,10 ; jc print_hex_word_1 ; if( b<10 ) ; add B,8 ;print_hex_word_1: ; add B,"0" ; out B ; mov B,D ; dec C ; jnz print_hex_word_loop ; ; ret ;end procedure print_hex_word }}} ;procedure print_hex_two_bytes {{{ ;This procedure prints two 8-bit numbers in hexadecimal. ;The first to be printed is passed on B, and the second on A. ;This prints these bytes in exact reverse order than print_hex_word print_hex_two_bytes: ;This procedure should be CALLed, and not JuMPed mov C,"0" ;Store the ASCII code for "0" ;print_first_nibble: mov D,B ;Copy B to D shr B shr B shr B shr B cmp B,10 jc print_hex_two_bytes_1 add B,"A"-"9"-1 print_hex_two_bytes_1: add B,C out B ;print_second_nibble: mov B,D mov D,"A"-"9"-1 and B,0Fh cmp B,10 jc print_hex_two_bytes_2 add B,D print_hex_two_bytes_2: add B,C out B ;print_third_nibble: mov B,A ;Copy B to A shr B shr B shr B shr B cmp B,10 jc print_hex_two_bytes_3 add B,D print_hex_two_bytes_3: add B,C out B ;print_fourth_nibble: and A,0Fh cmp A,10 jc print_hex_two_bytes_4 add A,D print_hex_two_bytes_4: add A,C out A ret ;end procedure print_hex_two_bytes }}} ;procedure print_byte {{{ ;This procedure prints a byte, but prints blank instead of special chars. ;The byte is passed on B. print_byte: ;This procedure should be CALLed, and not JuMPed cmp B,CR jz print_byte_blank cmp B,LF jz print_byte_blank cmp B,FF jz print_byte_blank out B ret print_byte_blank: mov B," " out B ret ;end procedure print_byte }}} ;procedure print_two_bytes {{{ ;This procedure prints two bytes, but prints blank instead of special chars. ;The first byte is passed on B, the second on A. print_two_bytes: ;This procedure should be CALLed, and not JuMPed cmp B,CR jz print_two_bytes_blank1 cmp B,LF jz print_two_bytes_blank1 cmp B,FF jz print_two_bytes_blank1 out B jr print_two_bytes_second print_two_bytes_blank1: mov B," " out B print_two_bytes_second: cmp A,CR jz print_two_bytes_blank2 cmp A,LF jz print_two_bytes_blank2 cmp A,FF jz print_two_bytes_blank2 out A ret print_two_bytes_blank2: mov A," " out A ret ;end procedure print_two_bytes }}} ;procedure dump_line {{{ ;DOC TO BE WRITTEN ;Memory position at AB dump_line: ;This procedure should be CALLed, and not JuMPed push AB mov [dump_line_pointer],AB call print_hex_word mov AB,": " out B out A mov [dump_line_counter],8 dump_line_loop1: mov CD,[dump_line_pointer] mov AB,[CD] inc CD inc CD mov [dump_line_pointer],CD call print_hex_two_bytes mov A," " out A dec [dump_line_counter] jnz dump_line_loop1 mov [dump_line_counter],8 pop CD dump_line_loop2: mov AB,[CD] call print_two_bytes inc CD inc CD dec [dump_line_counter] jnz dump_line_loop2 mov AB,0A0Dh out B out A ret dump_line_counter: res 1 dump_line_pointer: res 2 ;end procedure dump_line }}} end_address_label: