Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!uflorida!mailer.cc.fsu.edu!prism!ccastjr From: ccastjr@prism.gatech.EDU (COOOooOoooooOOOOoOOoOOooKIE!!!!!) Newsgroups: comp.sources.wanted Subject: Re: What does this assembler code do? Keywords: VAX, VMS, backup Message-ID: <18092@hydra.gatech.EDU> Date: 4 Dec 90 19:39:39 GMT References: Distribution: comp Organization: Georgia Institute of Technology Lines: 119 In article ralph@laas.fr writes: >The following embedded assembler code belongs to some C language code >for reading VAX VMS Backup tapes under Unix. Maybe this would compile >under Ultrix. If someone can translate this into straight C, I would >sure appreciate that, also. Here's the function: > >vdatetosec() >{ > asm("movl 4(ap),r0"); > asm("movl (r0)+,r2; movl (r0),r3; subl2 $2913970176,r2; sbwc $8164719,r3 "); > asm("ediv $10000000,r2,r0,r1"); >} > >Neither SPARCs nor 680x0s like this code! > >-- >Ralph P. Sobek Disclaimer: The above ruminations are my own. >ralph@laas.fr Addresses are ordered by importance. >ralph@laas.uucp, or ...!uunet!laas!ralph >If all else fails, try: sobek@eclair.Berkeley.EDU >=============================================================================== >Reliable software should kill people reliably! -Andy Mickel, Pascal News #13,78 Newsgroups: comp.sources.wanted Subject: Re: What does this assembler code do? Summary: Expires: References: Sender: Followup-To: Distribution: comp Organization: Georgia Institute of Technology Keywords: VAX, VMS, backup In article ralph@laas.fr writes: >The following embedded assembler code belongs to some C language code >for reading VAX VMS Backup tapes under Unix. Maybe this would compile >under Ultrix. If someone can translate this into straight C, I would >sure appreciate that, also. Here's the function: > >vdatetosec() >{ > asm("movl 4(ap),r0"); > asm("movl (r0)+,r2; movl (r0),r3; subl2 $2913970176,r2; sbwc $8164719,r3 "); > asm("ediv $10000000,r2,r0,r1"); >} > >Neither SPARCs nor 680x0s like this code! > first note: I treid to reply through mail, but my machine didn't like the address. The reason that doesn't work on non-DEC machines is that the assembler is machine specific.. and thus only works on Dec machines.. not on sparc's, not on 68K's, just on Dec's. See, most C compilers (esp. on unix) don't output executable, they output assembly code, which then gets passed to an assembler (this is transparent to you.. but there's an option to get it to stop in the middle).. all the "asm()" function does is say to the compiler "pass this text directly to the assembler" well.. basically :) Hmm.. the actual code isn't too clear.. > asm("movl 4(ap),r0"); ok.. movl means move a long word.. this instruction is saying "take the longword at ap+4 (using the ap as a pointer), and move it to the zero register (r0)" parenthesis means indirection. here's where the fun comes in.. ap is the argument pointer for "calls" functions in vax assembler.. all arguments are long words.. and all addresses are bytes.. thus ap+4 is the FIRST argument. > asm("movl (r0)+,r2; movl (r0),r3; subl2 $2913970176,r2; sbwc $8164719,r3 "); ok.. (r0)+ means use r0 as a pointer, and post imcrement it.. so.. the first two instrucions basically say "take what the first argument points to, move it to r2, take the next thing after that, and move it to r3).. since this is a movl, the post increment is automatically by 4 it could equivilently have been "movl (r0), r2; movl 4(r0),r3" with the small exception that r0 wwould still be pointing at r2, and not at r3. subl2 is subract longwords, 2 arguments. So, it's the same as r2 = r2 - $2913970176 (decimal) sbwc is subract with carry > asm("ediv $10000000,r2,r0,r1"); ediv is extended devision..and, unfortunately, I don't have the argument in my brain anymore.. oh..heh.. the TA for the assembler class we have here just came in (our class was in VAX assembler). ediv bottom, top, answer, remainder also, top is a QUAD word.. so it'd be r3,r2 concatinated..r3 being the most significant bits. r0 = r3r2 / $10000000 r1 = r3r2 % $10000000 (in C..where all are int) if it weren't for the direct use of registers, I'd probably be able to make this into soem C code.. unfortunately, I can't... I'll send this to said TA.. but he's REALLY busy right now, so he might not get back to you until MUCH later. Jon: this is off of comp.sources.wanted John -- Emporers Thought for the Day: | John E. Rudd jr. Only the insane have the strength to prosper; | ccastjr@prism.gatech.edu Only those who prosper judge what is sane. | (ex- kzin@ucscb.ucsc.edu) #include Send all comments, flames, and complaints to /dev/null.