Giter VIP home page Giter VIP logo

pcasm's People

Contributors

pacman128 avatar xfe-v02er avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pcasm's Issues

Why LE is necessary

Firstly I understand the difference between lev and mov in terms of the result they can achieve, put in simply

mov eax ebp  ;put the value in ebp register into eax register
lea eax [ebp] ;same as above, and they are equivalent 

However

mov eax,ebp+8 ;invalid register set size
lea eax,[ebp+8] ;calculate in sum of ebp value and 8, then assign it to eax

So what mov eax,ebp+8 is illegal while lea eax,[ebp+8] is OK? My book says

The value that MOV stores into EAX must be computed by the assembler
(that is, it must in the end be a constant)

But it make no sense to me! What is mean by CONSTANT? The obvious understanding it that the CONSTANT should be calculate by assembler/linker before the program run, BUT, think about mov eax,[ebp+8] is a LEGAL instruction, The assembler/linker has no way of knowing the value of [ebp+8](*(ebp+8) as C lingo) before the program run!

https://stackoverflow.com/questions/77416613/why-leaload-effective-address-is-necessary

Possibility to support 64-bit some day?

@pacman128 First of all, thank you very much for the book, it looks amazing.

As the title says, are there any plans to support 64-bit in the near future? I'm currently teaching myself assembly using my Linux system and I'm facing some issues with some material I have found online.

Some websites teach assembly while using Intel's syntax and some AT&T's, which is confusing me a lot.

By the way, would it be a problem if the book's style change a bit? I'm quite comfortable using LaTeX and one of my eccentricities is producing good-looking ebooks.

Right now I'm trying to mimic the look of this book which has one of the most appealing styles I have ever seen.

Are you open for such change or should I use it for my own version?

Cheers.

Tips on getting examples working on Windows 10 natively and on WSL

Hi,

Just thought I'd share some tips here on how to get the examples working on Windows 10.

Running natively on Windows 10

For the very first hello.asm example on Page 25. Run these in batch / command-prompt / Windows Terminal:

rem Set up the 32-bit environment for VC
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat"

rem Assemble the hello.asm example
nasm -f win32 -d COFF_TYPE hello.asm

rem Compile & link
cl hello.obj ms/asm_io.obj driver.c legacy_stdio_definitions.lib

In particular linking with legacy_stdio_definitions.lib was necessary as otherwise _scanf / _printf / etc cannot be found.

Running on WSL

As for running it on WSL (Ubuntu on Win10), it's a bit more complicated. Most distros are 64-bit only, so the user needs to install gcc-multilib, make sure to link with 32-bit C library, add the ability for the OS to run 32-bit executables, and then finally an additional workaround is necessary to make this all work on WSL.

# Assemble the I/O file (or use the Makefile to assemble everything at once)
cd linux
nasm -felf32 -d ELF_TYPE asm_io.asm
cd ..

# Install GCC
sudo apt install build-essential

# Install 32-bit C standard library
sudo apt-get install gcc-multilib

# Assemble the hello example
# Note: it's not the same as the Windows example, it has different includes, symbols without _, etc.
nasm -felf32 hello.asm

# Compile the driver
gcc -c -m32 driver.c

# Use GCC to link it all together (much easier than using LD directly)
gcc -L /usr/lib32 -lc -m32 linux/asm_io.o driver.o hello-linux.o -ohello-linux

Finally to actually run the 32-bit executable you need additional work. Most of these tips taken from this Stackoverflow answer and from Github:

# Install qemu
sudo apt install qemu-user-static

# Ignore warnings on this one
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic \
'\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' \
--mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'

# You MUST run this every time WSL starts. Probably best to add it to your .bashrc / .zshrc
sudo service binfmt-support start

# Add i386 architecture packages
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install g++:i386

And then run the executable:

./hello-linux

Enter a number: 1
Enter another number: 2
Register Dump # 1
EAX = 00000003 EBX = 00000003 ECX = 663025FF EDX = FEFF9A44
ESI = FE7BA000 EDI = FE7BA000 EBP = FEFF99F8 ESP = FEFF99D8
EIP = FEFFB5C7 FLAGS = 0206                PF
Memory Dump # 2 Address = FEFFE1BC
FEFFE1B0 65 72 20 6E 75 6D 62 65 72 3A 20 00 59 6F 75 20 "er number: ?You "
FEFFE1C0 65 6E 74 65 72 65 64 20 00 20 61 6E 64 20 00 2C "entered ? and ?,"
You entered 1 and 2, the sum of these is 3

Finally always make sure to run sudo service binfmt-support start in WSL on the first start. Probably best to keep it in the .bashrc / .zshrc file in $HOME.

Hope this helps anyone else trying out this book on Windows.

Really appreciate the free book @pacman128, it's an awesome resource for learning asm!

Cheers!

about the +56(00111000) one's complement

why the book says the +56(00111000) one's complement is 11000111 on the page 28 (Chapter2)

I think the one's complement and two's complement is the equal to 00111000, because it's a Positive integer

am i right?

wrong implemtation in sub_dump_regs which may cause Segmentation fault

try

        push 1;
        call sub_dump_regs
        push 2;
        call sub_dump_regs
        push 3
        pop eax
        pop ebx
        pop ecx

Which will introduce a Segmentation fault
The Segmentation fault will disappear by removing the debugging utilities i.e. sub_dump_regs

        push 1;
        push 2;
        push 3
        pop eax
        pop ebx
        pop ecx

Obvious sub_dump_regs introduce the problem

`first.asm` code fail to compile under Linux

Thanks for the Book Paul, very helpful.

While trying to run the first.asm code, I was not able to compile it under x86_64 Linux. GCC will complain citing architecture incompatibility issues. After a little bit of search I found out that ones needs to add the -m32 option to for it to correctly compile (along with installing gcc-multilib and g++-multilib packages before-head)

Also, assembling the asm_io.asm was not mentioned in section 1.4.3, although it is necessary, and it has a caveat where one needs to add the inline macro -d ELF_TYPE, this would only be noticed when reading the comments of the asm_io.asm file. For a beginner, and for his/her very first code, this will hinder a bit, and distract the learner on a quest on the web trying to find a solution.

I have submitted a pull request with some some details on the comments to the asm_io.asm file.

simplified_chinese compile failure

My system: ubuntu:18.04
Installed texlive texlive-science latex-cjk-english
The following errors have been encountered when using pdflatex pcasm

! Undefined control sequence.
try@size@range ...extract@rangefontinfo font@info 
                                                  <-*>@nil <@nnil 
l.69 \maketitle
               
? 

Is there a solution?

Introductory text mentions PowerPC-based Macs

pcasm1.tex says :

This is one reason why programs written for a Mac can not run on an IBM-type PC.

While I'm sure that this was true at the time the book was written, PowerPC-based Macs are a thing of the past now. Thus, this statement might be a tad misleading to some of the readers, especially seeing how they're expected to be absolute beginners in assembly/machine code related subjects. I suggest changing this to reference mobile phones, since they're probably the most widespread non-x86 devices nowadays, and readers will probably be familiar with them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.