Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!wuarchive!husc6!encore!jcallen From: jcallen@Encore.COM (Jerry Callen) Newsgroups: comp.lang.asm370 Subject: Register Display Summary: Tricky Code Follows Message-ID: <11573@encore.Encore.COM> Date: 11 Apr 90 15:55:06 GMT Reply-To: jcallen@encore.com (Jerry Callen) Organization: Encore Computer Corp, Marlboro, MA Lines: 51 >I am looking for an assembler macro that will convert the contents of a >register to printable characters. IBM is bound to have one floating >around. Can anybody lead me in the right direction? The following code fragment is a semi-slick way to convert a value in a register to printable hex. I didn't invent it; I suspect I learned it from either Dave Andrews or Clay Brice, my 360 (!) mentors in the early 1970's. It takes advantage of several funky 360/370 features: - The digits in the second operand of an UNPK instruction are not checked for validity. - The operands of UNPK are allowed to overlap and are processed right to left. - UNPK always supplies a zone nibble of "F", so we don't need to specify a complete translate table; we can get away with just the last 16 entries. WARNING: I don't have access to 370 right now and have not tested this code. However, I've used variations on it for years and I'd be surprised if I screwed it up (but then, it wouldn't be the first time I've screwed up...). -- Jerry "reformed TSO bigot, now hacking Unix" Callen jcallen@encore.com ********************************************************************** * * Convert a value in a register to printable hex. Some requirements * and assumptions: * * This is a subroutine in a larger program; that larger program has * established a base register, and its base is far enough back for * the HEXTAB equate to work (if this is puzzling, just try it; if * it doesn't assemble, you'll get the idea). * * The value to be converted is in R1. * * The return address is in R11 (linkage was via BAL R11,HEXCNVT). * * This code is NOT reentrant; it is easy to make it so. * HEXCNVT DS 0H ST R1,HEXVALUE save the value to convert UNPK HEXVALUE(9),HEXVALUE(5) spread out the nibbles TR HEXVALUE(8),HEXTAB translate to printable hex BR R11 return * DS 0F word align (not strictly necessary) HEXVALUE DS CL9 hex value ends up in 1st 8 bytes DC C'0123456789ABCDEF' HEXTAB EQU *-256 pretend we have a complete table