Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!columbia!rutgers!mtune!codas!cpsc6a!rtech!wrs!dg From: dg@wrs.UUCP (David Goodenough) Newsgroups: comp.misc Subject: Re: Assembly Language Message-ID: <309@wrs.UUCP> Date: Tue, 18-Aug-87 14:22:18 EDT Article-I.D.: wrs.309 Posted: Tue Aug 18 14:22:18 1987 Date-Received: Fri, 21-Aug-87 07:29:56 EDT References: <892@edge.UUCP> <7359@think.UUCP> <4180@ncoast.UUCP> Reply-To: dg@wrs.UUCP (David Goodenough) Organization: Wind River Systems, Emeryville, CA Lines: 94 In article <4180@ncoast.UUCP> robertd@ncoast.UUCP (Rob DeMarco) writes: > However, logically speaking, an assembler program is difficult to follow >and grasp. You would HAVE to "comment fiendishly" so the person can see what >it is doing. Logically on the human mind, a statement like this: > > IF A = 8 THEN GOTO 5000 > >is a little easier to follow then this: > > CPI 8H > JZ 0C00H I also do a fairly large amount of work in assembler, and I've found a very clean, simple method of commenting & explaining what's going on. Step 1: Write & debug the code in C Step 2: Copy the C source to a .Z file (assembler source) Step 3: Put a ';' (comment start character) in front of each line Step 4: Produce the opcodes to do what the C does Step 5: Debug (99% of the time with a listing in hand) So typical C code might be: strncpy(dest, source, count) char *dest, *source; { while (count-- && (*dest = *source)) { dest++; source++; } *dest = 0; } And the output: ;strncpy(dest, source, count) .var #dest 6 ; offset from ix of dest .var #source 8 ; offset from ix of source .var #count 6 ; offset from ix of count ;char *dest, *source; .extern _strncpy _strncpy: call #csv ; set up frame pointer ld c,(ix + #count) ; get count to bc ld b,(ix + #count + 1) ld e,(ix + #source); get source to de ld d,(ix + #source + 1) ld l,(ix + #dest) ; get dest to hl ld h,(ix + #dest + 1) /* as an aside, I use macros for the three ld pairs above: load b,c,#count * which expands to the first load pair */ ; { loop: ld a,b or c jr z,break ; exit loop if count == 0 dec bc ; count-- ld a,(de) ld (hl),a ; copy a byte or a ; and test for zero jr z,break ; exit if zero byte at end of string ; while (count-- && (*dest = *source)) ; { inc de ; dest++; inc hl ; source++; jr loop ; } break: ; we always hit here with zero in a ld (hl),a ; so save a zero byte to end ; *dest = 0; jp #cret ; clean up stack & return ; } Now any one who can't read and understand that with a minimal knowledge of z80 assembler needs to go back to school. -- dg@wrs.UUCP - David Goodenough +---+ | +-+-+ +-+-+ | +---+