1

I'm reading the textbook Computer Systems 4th Edition. The question below is in the context of the Pep/8 virtual computer. In the exercises I am given this question:

Convert the following assembly language pseudo-ops into hexadecimal machine language:

  1. .ASCII "Bear\x00"
  2. .BYTE 0xF8
  3. .WORD 790

I am trying to get these values converted to hex, but I cannot understand my textbook's explanation of the process, and I don't feel the book gives much of an explanation.

For the first answer I think it is a simple lookup in an ASCII conversion table:

42 65 61 72 00

The answers for this exercise are as follows:

  1. 42 65 61 72 00
  2. F8
  3. 0316

Despite knowing these answers I have no idea how to get the answers for 2 and 3

Here is the download link for the Pep/8 assembler and simulator. Here is the source code for the assembler.

  • It might help to just feed them into an assembler, and then look at the hexdump. You could use `nasm -fbin test.asm` / `hexdump -C test` (or whatever your favourite hex-dump tool is). The "bin" format doesn't have any headers or structure: the assembler just assembles bytes into a flat output file. – Peter Cordes Feb 18 '16 at 06:17
  • 1
    @PeterCordes This question is based upon Pep/8 architecture (unfortunately not tagged that way). The question is from the book [Computer Systems](https://books.google.com/books?id=PERY_m5yyl4C). As I recall Pep/8 is Big-Endian (someone can correct me if I'm wrong). If one were to use NASM to produce output for the `.WORD` its bytes wold be reversed so may not render the answer the OP was looking for. – Michael Petch Feb 18 '16 at 15:46
  • @MichaelPetch I just added a link to the page on GitHub as well as the download page. It is from Computer Systems. 4th edition. – ComputerScientist123 Feb 18 '16 at 15:52
  • 2
    `BYTE 0xF8` means that you want to generate a single byte in machine code with the value 0xF8. 0x means the value after is in hexadecimal notation. So literally the answer for that is `F8` . Since there is no base prefix on 790 it is considered decimal. You need to convert the decimal to hexadecimal which would be 0x0316. The hex bytes generated in machine language would be `03 16` in the case of a big endian architecture like Pep/8. – Michael Petch Feb 18 '16 at 16:12
  • Oh! Ok! Much better than the explanation in the book! Thank you, @MichaelPetch – ComputerScientist123 Feb 18 '16 at 16:24
  • What I failed to mention is that the `.WORD` pseudo-op says to generate a 2 byte (16-bit) value. – Michael Petch Feb 18 '16 at 16:28
  • So, if I have another question asking for: .BYTE 13, .ASCII "Frog\x00" and .WORD -6, then the answers would be D; 46 52 4F 47 00, and FFFFFFFFFFFFFFFA, respectively? For the first one, D, since it does not have 0x, it is the conversion from decimal to hex, right? @MichaelPetch – ComputerScientist123 Feb 18 '16 at 16:31
  • Almost. I gather you put -6 in a calculator that sign extended to 64 bits. Since it is `.WORD -6` it is 2 bytes (16-bits) so it would be `FF FA` – Michael Petch Feb 18 '16 at 16:35
  • Oh, that's right. I forgot about the 2 byte limit. Thanks! @MichaelPetch – ComputerScientist123 Feb 18 '16 at 16:36

1 Answers1

2

So number 2... Is in hexadecimal form.

you just need to change it to binary form with 8 bits

For example....

If you had 0xA7....

In base ten this is 167

The answer would be... In unsigned binary 10100111

This is how interpreted the question, is this what you meant? Do you have anymore information?

R.Hull
  • 126
  • 1
  • 8
  • Thank you! I didn't realize it was that simple. The book wasn't clear on the conversion process at all. – ComputerScientist123 Feb 18 '16 at 05:32
  • No problem, and I believe by word they mean 32 bit size binary word right? – R.Hull Feb 18 '16 at 05:40
  • In the book it says, "the .WORD command generates code for the loader. It always generates one word (two bytes) of code, not an arbitrary number of bytes." They use the example of .WORD 5 means .WORD 0x0030, which would mean "Generate one word with a value of 0030(hex)." – ComputerScientist123 Feb 18 '16 at 05:45
  • This is an assembly language? Is it one used today in production? Or one created for learning purposes? – R.Hull Feb 18 '16 at 05:48
  • It looks like the language the book is using most is Pep\8. – ComputerScientist123 Feb 18 '16 at 05:51
  • Please note that this answer is ambiguous. It does not take into account endianess, also there is no such thing as "*unsigned binary*" (the sign encoding is given by use/convention, not the numeral. 0A7h can be -87 or 167 but it is always 1010 0111) – Margaret Bloom Feb 18 '16 at 09:35
  • I added the answers to each of these questions above. I still don't know how to get the answers, I just looked them up in the back of the book. – ComputerScientist123 Feb 18 '16 at 15:34