some help pls with a routine?

  • Follow


Hi folks, hoping someone could help me with a routine that will read a
memory location and return a hex string of the byte value at that
location?
0
Reply xlar54 1/22/2011 7:59:10 AM

xlar54 wrote:

> Hi folks, hoping someone could help me with a routine that will read a
> memory location and return a hex string of the byte value at that
> location?


..p2align 4, 0x00
tHEX:
..word 0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730, 0x3830, 0x3930, 
0x4130, 0x4230, 0x4330, 0x4430, 0x4530, 0x4630
..word 0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731, 0x3831, 0x3931, 
0x4131, 0x4231, 0x4331, 0x4431, 0x4531, 0x4631
..word 0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632, 0x3732, 0x3832, 0x3932, 
0x4132, 0x4232, 0x4332, 0x4432, 0x4532, 0x4632
..word 0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533, 0x3633, 0x3733, 0x3833, 0x3933, 
0x4133, 0x4233, 0x4333, 0x4433, 0x4533, 0x4633
..word 0x3034, 0x3134, 0x3234, 0x3334, 0x3434, 0x3534, 0x3634, 0x3734, 0x3834, 0x3934, 
0x4134, 0x4234, 0x4334, 0x4434, 0x4534, 0x4634
..word 0x3035, 0x3135, 0x3235, 0x3335, 0x3435, 0x3535, 0x3635, 0x3735, 0x3835, 0x3935, 
0x4135, 0x4235, 0x4335, 0x4435, 0x4535, 0x4635
..word 0x3036, 0x3136, 0x3236, 0x3336, 0x3436, 0x3536, 0x3636, 0x3736, 0x3836, 0x3936, 
0x4136, 0x4236, 0x4336, 0x4436, 0x4536, 0x4636
..word 0x3037, 0x3137, 0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737, 0x3837, 0x3937, 
0x4137, 0x4237, 0x4337, 0x4437, 0x4537, 0x4637
..word 0x3038, 0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738, 0x3838, 0x3938, 
0x4138, 0x4238, 0x4338, 0x4438, 0x4538, 0x4638
..word 0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739, 0x3839, 0x3939, 
0x4139, 0x4239, 0x4339, 0x4439, 0x4539, 0x4639
..word 0x3041, 0x3141, 0x3241, 0x3341, 0x3441, 0x3541, 0x3641, 0x3741, 0x3841, 0x3941, 
0x4141, 0x4241, 0x4341, 0x4441, 0x4541, 0x4641
..word 0x3042, 0x3142, 0x3242, 0x3342, 0x3442, 0x3542, 0x3642, 0x3742, 0x3842, 0x3942, 
0x4142, 0x4242, 0x4342, 0x4442, 0x4542, 0x4642
..word 0x3043, 0x3143, 0x3243, 0x3343, 0x3443, 0x3543, 0x3643, 0x3743, 0x3843, 0x3943, 
0x4143, 0x4243, 0x4343, 0x4443, 0x4543, 0x4643
..word 0x3044, 0x3144, 0x3244, 0x3344, 0x3444, 0x3544, 0x3644, 0x3744, 0x3844, 0x3944, 
0x4144, 0x4244, 0x4344, 0x4444, 0x4544, 0x4644
..word 0x3045, 0x3145, 0x3245, 0x3345, 0x3445, 0x3545, 0x3645, 0x3745, 0x3845, 0x3945, 
0x4145, 0x4245, 0x4345, 0x4445, 0x4545, 0x4645
..word 0x3046, 0x3146, 0x3246, 0x3346, 0x3446, 0x3546, 0x3646, 0x3746, 0x3846, 0x3946, 
0x4146, 0x4246, 0x4346, 0x4446, 0x4546, 0x4646


64 bit solution (using above table):

..p2align 4,,15
..globl   _B2hex
..def     _B2hex; .scl 2; .type 32; .endef
_B2hex:
movzb    0x00(%rcx),%edx
leaq     tHEX(%rip),%rax
movzwl   0x00(%rax, %rdx, 2),%eax
ret


32 bit solution (using same table):

..p2align 4,,15
..globl   _B2hex
..def     _B2hex; .scl 2; .type 32; .endef
_B2hex:
movzb    0x00(%ecx),%edx
leaq     tHEX,%eax
movzwl   0x00(%eax, %edx, 2),%eax
ret


rCX holds the address of the byte, rAX returns
with a zero terminated string 00LH, where H is
the high, L the low nibble - if rAX is written
to memory, this is reversed to HL00...


Greetings from Augsburg

Bernhard Schornak
0
Reply Bernhard 1/22/2011 10:03:49 AM


"xlar54" posted:

> Hi folks, hoping someone could help me with a routine that will read a
> memory location and return a hex string of the byte value at that
> location?

Late with homework ?
I'm in good mood today, so OK:

read a memory location:

  mov al,[memory]      ;reads a byte from 'memory'
                       ;you better define this memory anywhere or
                       ;use a pointer ie:
 ;mov esi,memory
 ;mov al,[esi]

make a hex-string out from a byte in AL into AX:

 mov ah,al        ;save a copy into AH
 shr ah,4         ;mask high nibbly
 and al,0fh       ;mask low nibble
 cmp al,0ah
 jc L1            ;skip/jump if 0..9 -> 0x30..0x39    = "0".."9"
 add al,7         ;only if    10..15 -> 0x3A..0x3f +7 = "A".."F"
L1:               ;
 add al,30h       ;low nibble conversion done yet

cmp ah,0ah        ;same for high nibble in AH
 jc L2
 add ah,7
L2:
 add ah,30h
 ret              ;done

The highbyte in AX contains the higher value here, so if you
want a human readable character ordered format in AX, replace
the functions or XCHG AL,AH at the end.

Even I've seen and use myself something faster/smarter ...
it may satisfy your teacher for a short time anyway.
But be aware, some teachers may read this our group ... :)

__
wolfgang


0
Reply wolfgang 1/22/2011 4:35:56 PM

>
> Late with homework ?
> I'm in good mood today, so OK:
>

heh,no...Im in my late 30s and my x86 isn't as good as it used to
be :)  Thanks for the help though!
0
Reply xlar54 1/23/2011 5:57:42 AM

On Jan 22, 11:57=A0pm, xlar54 <scott.hut...@nospicedham.gmail.com>
wrote:
> > Late with homework ?
> > I'm in good mood today, so OK:
>
> heh,no...Im in my late 30s and my x86 isn't as good as it used to
> be :) =A0Thanks for the help though!


Actually full disclosure, Im *attempting* a ML monitor, much like you
used to see in the old 8-bit 6502 systems.  But I havent touched x86
in a long time. The memory model is much different, so Im having to
relearn alot of it.  Frankly I rarely finish these kinds of projects,
but I enjoy learning some things along the way.  With the way
segmentation works though in x86, Im not sure a ML monitor makes a lot
of sense.  Dunno.  A linear model would be nice, but protected mode
seems too intimidating, at least from where I currently am skillset-
wise.  Thanks to Bernhard also.
0
Reply xlar54 1/23/2011 6:07:20 AM

4 Replies
518 Views

(page loaded in 0.095 seconds)

Similiar Articles:













7/24/2012 8:40:45 PM


Reply: