; CIS-261
; encoding_x86_instructions.asm

; @topic W060111 Examples of x86 instruction encoding
; @brief Demonstrates binary encodings of instructions presented in <a href="http:;www.c-jump.com/bcc/c261c/CPU/x86/lecture.html" target="_blank">Encoding Real x86 Instructions</a> lecture

.386                ; Tells MASM to use Intel 80386 instruction set.
.MODEL FLAT         ; Flat memory model
option casemap:none ; Treat labels as case-sensitive

.CONST          ; Constant data segment

.STACK 100h     ; (default is 1-kilobyte stack)

.DATA           ; Begin initialized data segment

.CODE               ; Begin code segment
_main PROC          ; Beginning of code
    BYTE 000h, 0C1h                         ; ADD CL, AL                (13)
    BYTE 002h, 0C8h                         ; ADD CL, AL                (13)
    BYTE 001h, 0C1h                         ; add ecx, eax              (14)
    BYTE 003h, 01Dh, 0AAh, 0BBh, 0CCh, 0DDh ; ADD EDX, DISPLACEMENT     (15)
    BYTE 003h, 03Bh                         ; ADD EDI, [EBX]            (16)
    BYTE 003h, 046h, 0FFh                   ; ADD EAX, [ ESI + disp8 ]  (17)
    BYTE 003h, 09Dh, 011h, 022h, 033h, 044h ; ADD EBX, [ EBP + disp32 ] (18)
    BYTE 003h, 02Ch, 005h, 011h, 022h, 033h, 044h   ; ADD EBP, [ disp32 + EAX*1 ] (19)
    BYTE 003h, 00Ch, 0BBh                   ; ADD ECX, [ EBX + EDI*4 ]  (20)
    BYTE 10000000y, 00000101y, 90h, 90h, 90h, 90h, 90h, 90h, 90h, 90h ; ADD Immediate (21)
    BYTE 066h, 041h                         ; INC CX                    (23)
    BYTE 04h, 0EEh                          ; add al, constant          (25)
    BYTE 05h, 0AAh, 0BBh, 0CCh, 0DDh        ; add eax, constant         (25)
    ret
    
_main ENDP
END _main       ; Marks the end of the module and sets the program entry point label