win

Assembly process, nuggets MD does not seem to support flow chart (khan), I give md flow chart code and corresponding pictures.

St =>start: start op1=> Operation: edit program op2=> Operation: assemble (masM)(.lst) op3=> Operation: link op4=>operation: Cond1 =>condition: syntax error? (.crf) cond2=>condition: I2 => InputOutput: target program file (.obj) i3=> InputOutput: executable file (.exe.map) e=>end: End of st - > op1 - > i1 - > op2 - > cond1 cond1 (yes) - > op1 cond1 (no) - > i2 - > op3 - > i3 - > op4 - > cond2 cond2 (yes) - > e cond2 (no) - > op1Copy the code

The win on the field

Win10 debug environment setup, I will not say more, online search, a lot of. To write the source code directly, put the data into AX and bx and add them:

assume cs:hw

hw segment
	mov ax, 1200h
	mov bx, 0034h 
	add ax, bx

	mov ax, 4c00h
	int 21h
hw ends

end
Copy the code

After assembly language source program is assembled by MASM, it can produce three files: object file (.obj), list file (.lst), cross-reference file (.crf).

The linker can assemble one or more independent object files and subroutines and variables defined in library files (.lib) into a relocatable executable (.exe).

During connection, in addition to generating executable files (.exe), you can also generate corresponding memory image files (.map) according to user’s specification.


Quickly generate

Add a semicolon “;” to the end of the masm command line Obj files are generated directly, ignoring intermediate files, list files (.lst), and cross-reference files (.crf).

Similarly, add a semicolon to the end of the link command line, ignore the memory image file (.map), and directly generate the.exe file.


The debug debugging

You can debug the generated. Exe and view the register status using R. Use u to view other instructions.

T can enter single step debugging

P can end the program

The full instructions are as follows:

  • N filename

The filename parameter includes the primary filename and extension. Specify drive letters and paths if necessary.

  • L [addr]

Load the file specified by the N command into memory with addr indicating the starting address to store the loaded file. If not specified, the default address is CS:0100.

  • D [range]

Displays the contents of memory cells in the specified range.

  • R [register_name]

Displays the contents of one or all 16-bit registers in the CPU. The contents of the flag register are the states (set/reset) of each flag bit, and each state is represented by two characters.

Sign a setting reset
Overflow OF OV NV
The direction of a DF DN UP
Interrupt a IF EI DI
The sign bit SF, NG PL
Zero ZF ZR NZ
Auxiliary carry AF AC NA
Parity bit PF PE PO
Carry a CF CY NC
  • A [address]

To translate assembly instructions input directly from the keyboard into object code and store in memory cells.

  • U [range]

Disassemble the object code in the specified memory into an 8086/8088 assembly instruction format and display it on the screen.

  • G [= addr [addr1 [, addr2 [,…]]]]

Execute in-memory programs continuously.

  • Run commands T and P in a single step

Both commands execute only one instruction. The difference between them is that the execution of the call instruction of the subroutine by the T command is transferred to the corresponding subroutine, while the execution of the whole subroutine by the P command is executed as one instruction.


mac

On MAC, it is relatively simple. Use Homebrew to install NASM and use NASM -V to confirm whether the installation is successful

brew install nasm
Copy the code

global _MAIN

_MAIN:
	mov ax, 1200h
	mov bx, 0034h
	add ax, bx
	
	mov rax,0x2000001
	mov rdi,0
	syscall
Copy the code

Assembly code actually changes all the time. As a non-assembly programmer, you can actually see it. The principle is similar. Use nasm to generate.obj file, use GCC to generate.out file (need to specify the entry with -e, here is _MAIN), execute.