🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #499

Poser on abs() function in asm. lang.

#499
From: Shankar Ramakrishnan
Date: Sun, 26 Jul 1992 21:55
19 lines
1302 bytes
While I went through the object code generated by Turbo C for the 
integer abs() function, I saw something like this:
  or ax,ax
  js done
  neg ax
done:
This has 6 bytes of code. I wondered whether there could be a shorter
code, and yes, I came up with one that takes only 5 bytes. But instead
of posting it on the net, I am leaving it as a puzzle to be solved by
readers of this net.
The problem is as follows: given an integer in AX, find a routine that
has 5 bytes or less that returns the absolute value in AX. Assume 
nothing about the contents of other registers or flags.
Please DO NOT post your answers on the net. Instead, send your solution
by email to me(shankar@ecn.purdue.edu). The names of the first 10
people who give the correct solution will be posted by me on this net.
Good luck.
-Shankar
Technical Details
Message-ID: <1992Jul26.215541.4461@noose.ecn.purdue.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sdd.hp.com!news.cs.indiana.edu!noose.ecn.purdue.edu!ec.ecn.purdue.edu!shankar

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sdd.hp.com!news.cs.indiana.edu!noose.ecn.purdue.edu!ec.ecn.purdue.edu!shankar
From: shankar@ec.ecn.purdue.edu (Shankar Ramakrishnan)
Subject: Poser on abs() function in asm. lang.
Message-ID: <1992Jul26.215541.4461@noose.ecn.purdue.edu>
Sender: news@noose.ecn.purdue.edu (USENET news)
Organization: Purdue University Engineering Computer Network
Date: Sun, 26 Jul 1992 21:55:41 GMT
Lines: 19