Friday, 28 April 2017

Assembly Language : 8086 Assembler Tutorial Part 9

Assembly Language programming : 8086 Assembler Tutorial (Part 9)

The Stack

Stack is an area of memory for keeping temporary data. Stack is used by CALL instruction to keep return address for procedure, RET instruction gets this value from the stack and returns to that offset. Quite the same thing happens when INT instruction calls an interrupt, it stores in stack flag register, code segment and offset. IRET instruction is used to return from interrupt call.

We can also use the stack to keep any other data,
there are two instructions that work with the stack:

PUSH - stores 16 bit value in the stack.

POP - gets 16 bit value from the stack.

Syntax for PUSH instruction:

PUSH REG
PUSH SREG
PUSH memory
PUSH immediate
REG: AX, BX, CX, DX, DI, SI, BP, SP.

SREG: DS, ES, SS, CS.

memory: [BX], [BX+SI+7], 16 bit variable, etc...

immediate: 5, -24, 3Fh, 10001101b, etc...


Syntax for POP instruction:

POP REG
POP SREG
POP memory
REG: AX, BX, CX, DX, DI, SI, BP, SP.

SREG: DS, ES, SS, (except CS).

memory: [BX], [BX+SI+7], 16 bit variable, etc...



Notes:

  • PUSH and POP work with 16 bit values only!
  • Note: PUSH immediate works only on 80186 CPU and later!


The stack uses LIFO (Last In First Out) algorithm,
this means that if we push these values one by one into the stack:
1, 2, 3, 4, 5
the first value that we will get on pop will be 5, then 4, 3, 2, and only then 1.



It is very important to do equal number of PUSHs and POPs, otherwise the stack maybe corrupted and it will be impossible to return to operating system. As you already know we use RET instruction to return to operating system, so when program starts there is a return address in stack (generally it's 0000h).

PUSH and POP instruction are especially useful because we don't have too much registers to operate with, so here is a trick:

  • Store original value of the register in stack (using PUSH).
  • Use the register for any purpose.
  • Restore the original value of the register from stack (using POP).

Here is an example:


ORG    100h

MOV    AX, 1234h
PUSH   AX          ; store value of AX in stack.

MOV    AX, 5678h   ; modify the AX value.

POP    AX          ; restore the original value of AX.

RET

END


Another use of the stack is for exchanging the values,
here is an example:


ORG    100h

MOV    AX, 1212h   ; store 1212h in AX.
MOV    BX, 3434h   ; store 3434h in BX


PUSH   AX          ; store value of AX in stack.
PUSH   BX          ; store value of BX in stack.

POP    AX          ; set AX to original value of BX.
POP    BX          ; set BX to original value of AX.

RET

END

The exchange happens because stack uses LIFO (Last In First Out) algorithm, so when we push 1212h and then 3434h, on pop we will first get 3434h and only after it 1212h.




The stack memory area is set by SS (Stack Segment) register, and SP (Stack Pointer) register. Generally operating system sets values of these registers on program start.

"PUSH source" instruction does the following:

  • Subtract 2 from SP register.
  • Write the value of source to the address SS:SP.

"POP destination" instruction does the following:

  • Write the value at the address SS:SP to destination.
  • Add 2 to SP register.

The current address pointed by SS:SP is called the top of the stack.

For COM files stack segment is generally the code segment, and stack pointer is set to value of 0FFFEh. At the address SS:0FFFEh stored a return address for RET instruction that is executed in the end of the program.

You can visually see the stack operation by clicking on [Stack] button on emulator window. The top of the stack is marked with "<" sign.








  emu8086 is better than NASM, MASM or TASM

Tag: 8086 Assembler, 8086 microprocessors instruction, assembly code, Assembly coding, assembly guide, assembly instruction, assembly language, assembly language instruction set, assembly language programming, Assembly program, assembly programming, capital letter, character convert, complete 8086 instruction sets microprocessors, complete instruction timing and instruction sets for 8086 microprocessors, conversion of characters in assembly language programming 8086, convert, emu8086, instruction complete set, instruction set complete for 8086, instruction sets, instruction sets for 8086, Lower case, Lowercase, print the small character into capital letter, programming 8086 assembly language conversion of small characters to capital, small letter, text string convert, Tutorial,


Assembly Language : 8086 Assembler Tutorial Part 12

Assembly Language : 8086 Assembler Tutorial Part 11

Assembly Language : 8086 Assembler Tutorial Part 10

Assembly Language : 8086 Assembler Tutorial Part 9

Assembly Language : 8086 Assembler Tutorial Part 8

Assembly Language : 8086 Assembler Tutorial Part 7

Assembly Language : 8086 Assembler Tutorial Part 6

Assembly Language : 8086 Assembler Tutorial Part 5

Assembly Language : 8086 Assembler Tutorial Part 4

Assembly Language : 8086 Assembler Tutorial Part 3

Assembly Language : 8086 Assembler Tutorial Part 2

Assembly Language : 8086 Assembler Tutorial Part 1

Assembly Language Programming : Complete 8086 instruction sets

Assembly Language Programming : I/O ports - IN/OUT instructions 

Assembly Language programming : Emu8086 Assembler Compiling and MASM / TASM compatibility

Assembly Language - string convert - Lowercase , Uppercase

for programming : the language of Number

Assembly Language - Complete Instruction Set and Instruction Timing of 8086 microprocessors

Assembly Language programming : A list of emulator supported interrupts

Assembly Language Programming : Emu8086 Overview, Using Emulator, Virtual Drives

Assembly Language Programming : All about Memory - Global Memory Table and Custom Memory Map

buy me  a cup of coffee

My Paypal Account is :  ksw.industries@gmail.com

Send me any small amount of money is welcome.
buy me  a cup of coffee

 ___________________________________________


Need More Detail ?   contact me !!


My Paypal Account is :   ksw.industries@gmail.com
buy me  a cup of coffee
Send me any small amount of money is welcome.

___________________________________________


Don't know how to send money ?   Click here for detail about Paypal account.
About PayPal Payment Methods

What type of PayPal accounts is better.
 


Don't have money? OK! Here is another way to get the program.
how to get my program - Free of charge







Assembly Language - string convert - Lowercase , Uppercase

Assembly code : Convert String  - Lower Case , Upper Case

Assembly program, Assembly code, Assembly coding, convert, Lowercase, Uppercase, Lower case, Upper case, capital letter, string convert, character convert, print the small character into capital letter, conversion of characters in assembly language programming 8086, emu8086, programming 8086 assembly language conversion of small characters to capital, assembly language programming, assembly language, assembly programming.

Assembly Language 8086 convert small character to capital letter






;CREATE A PROGRAM THAT WILL ASK FOR A SMALL LETTER
;AND OUTPUT IT IN CAPITAL LETTER



@pc macro char
mov ah,02h
mov dl,char
int 21h
endm

@ps macro st
mov ah,09h
lea dx,st
int 21h
endm


cseg segment para 'code'
assume cs:cseg;ss:cseg;ds:cseg;es:cseg
org 100h

start: jmp begin

dianacustodio db ?
str1 db 'Input a character: $'
str2 db 10,13,'Output: $'


begin:
mov ax,03h    ;clear
int 10h        ;clear

@ps str1    ;input a char

mov ah,01h    ;interrupt for inputing a char
int 21h


mov dianacustodio,al ;put the character from al register to dianacustodio variable

cmp dianacustodio,97    ;compare if the character inside the dianacustodio variable is greaterthan or equal to 97(ASCII)
jge covert_now ;if greater than or equal to 97,then jump to convert_now label.

cmp dianacustodio,123
jge exit ;if 123 or greater, terminate the program

cmp dianacustodio,96
jle exit ;exit again if the input is not a small character

convert_now:
sub dianacustodio,32 ;subtract 32 decimal to convert the character to capital
@ps str2
@pc dianacustodio ;then print

exit:

int 20h
cseg ends
end start






  emu8086 is better than NASM, MASM or TASM

Tag: 8086 Assembler, 8086 microprocessors instruction, assembly code, Assembly coding, assembly guide, assembly instruction, assembly language, assembly language instruction set, assembly language programming, Assembly program, assembly programming, capital letter, character convert, complete 8086 instruction sets microprocessors, complete instruction timing and instruction sets for 8086 microprocessors, conversion of characters in assembly language programming 8086, convert, emu8086, instruction complete set, instruction set complete for 8086, instruction sets, instruction sets for 8086, Lower case, Lowercase, print the small character into capital letter, programming 8086 assembly language conversion of small characters to capital, small letter , string convert, Tutorial, Upper case, Uppercase, Text string


Assembly Language : 8086 Assembler Tutorial Part 12

Assembly Language : 8086 Assembler Tutorial Part 11

Assembly Language : 8086 Assembler Tutorial Part 10

Assembly Language : 8086 Assembler Tutorial Part 9

Assembly Language : 8086 Assembler Tutorial Part 8

Assembly Language : 8086 Assembler Tutorial Part 7

Assembly Language : 8086 Assembler Tutorial Part 6

Assembly Language : 8086 Assembler Tutorial Part 5

Assembly Language : 8086 Assembler Tutorial Part 4

Assembly Language : 8086 Assembler Tutorial Part 3

Assembly Language : 8086 Assembler Tutorial Part 2

Assembly Language : 8086 Assembler Tutorial Part 1

Assembly Language Programming : Complete 8086 instruction sets

Assembly Language Programming : I/O ports - IN/OUT instructions 

Assembly Language programming : Emu8086 Assembler Compiling and MASM / TASM compatibility

Assembly Language - string convert - Lowercase , Uppercase

for programming : the language of Number

Assembly Language - Complete Instruction Set and Instruction Timing of 8086 microprocessors

Assembly Language programming : A list of emulator supported interrupts

Assembly Language Programming : Emu8086 Overview, Using Emulator, Virtual Drives

Assembly Language Programming : All about Memory - Global Memory Table and Custom Memory Map

buy me  a cup of coffee

My Paypal Account is :  ksw.industries@gmail.com

Send me any small amount of money is welcome.
buy me  a cup of coffee

 ___________________________________________


Need More Detail ?   contact me !!


My Paypal Account is :   ksw.industries@gmail.com
buy me  a cup of coffee
Send me any small amount of money is welcome.

___________________________________________


Don't know how to send money ?   Click here for detail about Paypal account.
About PayPal Payment Methods

What type of PayPal accounts is better.
 


Don't have money? OK! Here is another way to get the program.
how to get my program - Free of charge






Friday, 21 April 2017

Assembly Language : 8086 Assembler Tutorial Part 8

Assembly Language programming : 8086 Assembler Tutorial (Part 8)

Procedures

Procedure is a part of code that can be called from your program in order to make some specific task. Procedures make program more structural and easier to understand. Generally procedure returns to the same point from where it was called.

The syntax for procedure declaration:

name PROC

      ; here goes the code
      ; of the procedure ...

RET
name ENDP

name - is the procedure name, the same name should be in the top and the bottom, this is used to check correct closing of procedures.

Probably, you already know that RET instruction is used to return to operating system. The same instruction is used to return from procedure (actually operating system sees your program as a special procedure).

PROC and ENDP are compiler directives, so they are not assembled into any real machine code. Compiler just remembers the address of procedure.

CALL instruction is used to call a procedure.

Here is an example:


ORG    100h

CALL   m1

MOV    AX, 2

RET                   ; return to operating system.

m1     PROC
MOV    BX, 5
RET                   ; return to caller.
m1     ENDP

END


The above example calls procedure m1, does MOV BX, 5, and returns to the next instruction after CALL: MOV AX, 2.

There are several ways to pass parameters to procedure, the easiest way to pass parameters is by using registers, here is another example of a procedure that receives two parameters in AL and BL registers, multiplies these parameters and returns the result in AX register:


ORG    100h

MOV    AL, 1
MOV    BL, 2

CALL   m2
CALL   m2
CALL   m2
CALL   m2

RET                   ; return to operating system.

m2     PROC
MUL    BL             ; AX = AL * BL.
RET                   ; return to caller.
m2     ENDP

END


In the above example value of AL register is update every time the procedure is called, BL register stays unchanged, so this algorithm calculates 2 in power of 4,
so final result in AX register is 16 (or 10h).




Here goes another example,
that uses a procedure to print a Hello World! message:


ORG    100h

LEA    SI, msg        ; load address of msg to SI.

CALL   print_me

RET                   ; return to operating system.

; ==========================================================
; this procedure prints a string, the string should be null
; terminated (have zero in the end),
; the string address should be in SI register:
print_me     PROC

next_char:
    CMP  b.[SI], 0    ; check for zero to stop
    JE   stop         ;

    MOV  AL, [SI]     ; next get ASCII char.

    MOV  AH, 0Eh      ; teletype function number.
    INT  10h          ; using interrupt to print a char in AL.

    ADD  SI, 1        ; advance index of string array.

    JMP  next_char    ; go back, and type another char.

stop:
RET                   ; return to caller.
print_me     ENDP
; ==========================================================

msg    DB  'Hello World!', 0   ; null terminated string.

END


"b." - prefix before [SI] means that we need to compare bytes, not words. When you need to compare words add "w." prefix instead. When one of the compared operands is a register it's not required because compiler knows the size of each register.







  emu8086 is better than NASM, MASM or TASM

Tag: assembly language, assembly instruction, assembly programming, assembly code, assembly guide, emu8086, 8086 microprocessors instruction, instruction sets, instruction sets for 8086, instruction complete set, instruction set complete for 8086, assembly language instruction set, complete 8086 instruction sets microprocessors, complete instruction timing and instruction sets for 8086 microprocessors, 8086 Assembler, Tutorial

Assembly Language : 8086 Assembler Tutorial Part 12

Assembly Language : 8086 Assembler Tutorial Part 11

Assembly Language : 8086 Assembler Tutorial Part 10

Assembly Language : 8086 Assembler Tutorial Part 9

Assembly Language : 8086 Assembler Tutorial Part 8

Assembly Language : 8086 Assembler Tutorial Part 7

Assembly Language : 8086 Assembler Tutorial Part 6

Assembly Language : 8086 Assembler Tutorial Part 5

Assembly Language : 8086 Assembler Tutorial Part 4

Assembly Language : 8086 Assembler Tutorial Part 3

Assembly Language : 8086 Assembler Tutorial Part 2

Assembly Language : 8086 Assembler Tutorial Part 1

Assembly Language Programming : Complete 8086 instruction sets

Assembly Language Programming : I/O ports - IN/OUT instructions 

Assembly Language programming : Emu8086 Assembler Compiling and MASM / TASM compatibility

Assembly Language - string convert - Lowercase , Uppercase

for programming : the language of Number

Assembly Language - Complete Instruction Set and Instruction Timing of 8086 microprocessors

Assembly Language programming : A list of emulator supported interrupts

Assembly Language Programming : Emu8086 Overview, Using Emulator, Virtual Drives

Assembly Language Programming : All about Memory - Global Memory Table and Custom Memory Map

buy me  a cup of coffee

My Paypal Account is :  ksw.industries@gmail.com

Send me any small amount of money is welcome.
buy me  a cup of coffee

 ___________________________________________


Need More Detail ?   contact me !!


My Paypal Account is :   ksw.industries@gmail.com
buy me  a cup of coffee
Send me any small amount of money is welcome.

___________________________________________


Don't know how to send money ?   Click here for detail about Paypal account.
About PayPal Payment Methods

What type of PayPal accounts is better.
 


Don't have money? OK! Here is another way to get the program.
how to get my program - Free of charge





Monday, 17 April 2017

Treat Your Knee And Joint Pain Naturally Using A Natural Remedy

Eliminate Knee and Joint Pain in Just 10 Days!

There are several factors that can be causing knees or joint pain. However, according to professionals, the most common cause of knee pain is the aftermath of excessive physical exertion. Knee pain can be caused by bone density, wear, and tear of muscles and tissues.

Because most people consider knee pain to be synonymous with weakness and age, they rarely complain about this condition. Due to this mentality, several people will tolerate knee pains until it's too late.

What most people don't know is that knee pains are common, and they can happen to any person of any age and gender.

If the pain is not eliminated in time, it can cause damage and affect the shifting of the knee. You can easily treat your knee and joint pain naturally using a natural remedy and experience pain relief within a few days.

There are a few other factors that can cause knee and joint pain. Some of them include the deficiency of vital nutrients in the body such as calcium, vitamin D, and iron. Deficiency of vitamin D often hinders optimum bone health. Lack of calcium, on the other hand, makes the bones thin and brittle. People who suffer from vitamin D deficiency complain of mild pains in the knees and joints.

People who lack vitamin D and calcium are at a high risk of suffering from arthritis or an inflammation of the joints. There are two main kinds of arthritis including rheumatoid and osteo. Both of them affect the joints differently.

. Rheumatoid Arthritis: is caused by an immune disorder that leads to the inflammation of the synovial membrane. When it is not treated, it can eventually lead to bone loss.

. Osteorthritis: This is the wearing out of the cartilage found between bones. When it wears out, the bones grate each other.

Prevention of Knee and Joint Pains

As most people say, prevention is the best form of cure. Therefore, you can easily avoid experiencing pain in the future by modifying your lifestyle. If you experience knee pain for over a week, then this is an indication of other serious problems such as osteoporosis, arthritis, and other related bone complications. For you to evade these serious conditions, you should always consume a diet that is rich in vitamins, magnesium, and bromelain.

Remedy

Whichever form of arthritis or joint pains you are experiencing, there are natural remedies that can help reduce the pain and ease the symptoms. One remedy that has been proved to work is cinnamon, pineapple, and orange juice smoothie.


When the smoothie is consumed daily, it helps in relieving knee and joint pains. This is because the smoothie contains anti-inflammatory ingredients, silicon, magnesium, bromelain and vitamin C. All these nutrients make the tendons and ligaments stronger.

My Paypal Account is :  ksw.industries@gmail.com

Send me any small amount of money is welcome.
buy me  a cup of coffee

 ___________________________________________


Need More Detail ?   contact me !!

My Paypal Account is :   ksw.industries@gmail.com
buy me  a cup of coffee
Send me any small amount of money is welcome.

___________________________________________


Don't know how to send money ?   Click here for detail about Paypal account.
About PayPal Payment Methods

What type of PayPal accounts is better.
 


Don't have money? OK! Here is another way to get the program.
how to get my program - Free of charge


Assembly Language : 8086 Assembler Tutorial Part 7

Assembly Language programming : 8086 Assembler Tutorial (Part 7)

Program Flow Control

Controlling the program flow is a very important thing, this is where your program can make decisions according to certain conditions.


  • Unconditional Jumps

    The basic instruction that transfers control to another point in the program is JMP.

    The basic syntax of JMP instruction:
    JMP label
    To declare a label in your program, just type its name and add ":" to the end, label can be any character combination but it cannot start with a number, for example here are 3 legal label definitions:
    label1:
    label2:
    a:
    Label can be declared on a separate line or before any other instruction, for example:
    x1:
    MOV AX, 1

    x2: MOV AX, 2
    Here is an example of JMP instruction:

    
    ORG    100h
    
    MOV    AX, 5          ; set AX to 5.
    MOV    BX, 2          ; set BX to 2.
    
    JMP    calc           ; go to 'calc'.
    
    back:  JMP stop       ; go to 'stop'.
    
    calc:
    ADD    AX, BX         ; add BX to AX.
    JMP    back           ; go 'back'.
    
    stop:
    
    RET                   ; return to operating system.
    
    END                   ; directive to stop the compiler.

    Of course there is an easier way to calculate the some of two numbers, but it's still a good example of JMP instruction.
    As you can see from this example JMP is able to transfer control both forward and backward. It can jump anywhere in current code segment (65,535 bytes).


  • Short Conditional Jumps

    Unlike JMP instruction that does an unconditional jump, there are instructions that do a conditional jumps (jump only when some conditions are in act). These instructions are divided in three groups, first group just test single flag, second compares numbers as signed, and third compares numbers as unsigned.

    Jump instructions that test single flag

    Instruction Description Condition Opposite Instruction
    JZ , JE Jump if Zero (Equal).  ZF = 1 JNZ, JNE
    JC , JB, JNAE Jump if Carry (Below, Not Above Equal).  CF = 1 JNC, JNB, JAE
    JS Jump if Sign.  SF = 1 JNS
    JO Jump if Overflow.  OF = 1 JNO
    JPE, JP Jump if Parity Even.  PF = 1 JPO

    JNZ , JNE Jump if Not Zero (Not Equal).  ZF = 0 JZ, JE
    JNC , JNB, JAE Jump if Not Carry (Not Below, Above Equal).  CF = 0 JC, JB, JNAE
    JNS Jump if Not Sign.  SF = 0 JS
    JNO Jump if Not Overflow.  OF = 0 JO
    JPO, JNP Jump if Parity Odd (No Parity).  PF = 0 JPE, JP


    As you can see there are some instructions that do that same thing, that's correct, they even are assembled into the same machine code, so it's good to remember that when you compile JE instruction - you will get it disassembled as: JZ.
    Different names are used to make programs easier to understand and code.


    Jump instructions for signed numbers

    Instruction Description Condition Opposite Instruction
    JE , JZ Jump if Equal (=).
    Jump if Zero.
    ZF = 1 JNE, JNZ
    JNE , JNZ Jump if Not Equal (<>).
    Jump if Not Zero.
    ZF = 0 JE, JZ
    JG , JNLE Jump if Greater (>).
    Jump if Not Less or Equal (not <=).
    ZF = 0
    and
    SF = OF
    JNG, JLE
    JL , JNGE Jump if Less (<).
    Jump if Not Greater or Equal (not >=).
    SF <> OF JNL, JGE
    JGE , JNL Jump if Greater or Equal (>=).
    Jump if Not Less (not <).
    SF = OF JNGE, JL
    JLE , JNG Jump if Less or Equal (<=).
    Jump if Not Greater (not >).
    ZF = 1
    or
    SF <> OF
    JNLE, JG


    <> - sign means not equal.


    Jump instructions for unsigned numbers

    Instruction Description Condition Opposite Instruction
    JE , JZ Jump if Equal (=).
    Jump if Zero.
    ZF = 1 JNE, JNZ
    JNE , JNZ Jump if Not Equal (<>).
    Jump if Not Zero.
    ZF = 0 JE, JZ
    JA , JNBE Jump if Above (>).
    Jump if Not Below or Equal (not <=).
    CF = 0
    and
    ZF = 0
    JNA, JBE
    JB , JNAE, JC Jump if Below (<).
    Jump if Not Above or Equal (not >=).
    Jump if Carry.
    CF = 1 JNB, JAE, JNC
    JAE , JNB, JNC Jump if Above or Equal (>=).
    Jump if Not Below (not <).
    Jump if Not Carry.
    CF = 0 JNAE, JB
    JBE , JNA Jump if Below or Equal (<=).
    Jump if Not Above (not >).
    CF = 1
    or
    ZF = 1
    JNBE, JA


    Generally, when it is required to compare numeric values CMP instruction is used (it does the same as SUB (subtract) instruction, but does not keep the result, just affects the flags).

    The logic is very simple, for example:
    it's required to compare 5 and 2,
    5 - 2 = 3
    the result is not zero (Zero Flag is set to 0).

    Another example:
    it's required to compare 7 and 7,
    7 - 7 = 0
    the result is zero! (Zero Flag is set to 1 and JZ or JE will do the jump).

    Here is an example of CMP instruction and conditional jump:

    
    include emu8086.inc
    
    ORG    100h
    
    MOV    AL, 25     ; set AL to 25.
    MOV    BL, 10     ; set BL to 10.
    
    CMP    AL, BL     ; compare AL - BL.
    
    JE     equal      ; jump if AL = BL (ZF = 1).
    
    PUTC   'N'        ; if it gets here, then AL <> BL,
    JMP    stop       ; so print 'N', and jump to stop.
    
    equal:            ; if gets here,
    PUTC   'Y'        ; then AL = BL, so print 'Y'.
    
    stop:
    
    RET               ; gets here no matter what.
    
    END


    Try the above example with different numbers for AL and BL, open flags by clicking on [FLAGS] button, use [Single Step] and see what happens, don't forget to recompile and reload after every change (use F5 shortcut). 




  • All conditional jumps have one big limitation, unlike JMP instruction they can only jump 127 bytes forward and 128 bytes backward (note that most instructions are assembled into 3 or more bytes).

    We can easily avoid this limitation using a cute trick:

    • Get a opposite conditional jump instruction from the table above, make it jump to label_x.
    • Use JMP instruction to jump to desired location.
    • Define label_x: just after the JMP instruction.
    label_x: - can be any valid label name.

    Here is an example:

    
    include emu8086.inc
    
    ORG    100h
    
    MOV    AL, 25     ; set AL to 25.
    MOV    BL, 10     ; set BL to 10.
    
    CMP    AL, BL     ; compare AL - BL.
    
    
    JNE    not_equal  ; jump if AL <> BL (ZF = 0).
    JMP    equal
    not_equal:
    
    
    ; let's assume that here we
    ; have a code that is assembled
    ; to more then 127 bytes...
    
    
    PUTC   'N'        ; if it gets here, then AL <> BL,
    JMP    stop       ; so print 'N', and jump to stop.
    
    equal:            ; if gets here,
    PUTC   'Y'        ; then AL = BL, so print 'Y'.
    
    stop:
    
    RET               ; gets here no matter what.
    
    END




Another, yet rarely used method is providing an immediate value instead of a label. When immediate value starts with a '$' character relative jump is performed, otherwise compiler calculates instruction that jumps directly to given offset. For example:

ORG    100h

; unconditional jump forward:
; skip over next 2 bytes,
JMP $2
a DB 3    ; 1 byte.
b DB 4    ; 1 byte.

; JCC jump back 7 bytes:
; (JMP takes 2 bytes itself)
MOV BL,9
DEC BL      ; 2 bytes.
CMP BL, 0   ; 3 bytes.
JNE $-7

RET

END









  emu8086 is better than NASM, MASM or TASM

Tag: assembly language, assembly instruction, assembly programming, assembly code, assembly guide, emu8086, 8086 microprocessors instruction, instruction sets, instruction sets for 8086, instruction complete set, instruction set complete for 8086, assembly language instruction set, complete 8086 instruction sets microprocessors, complete instruction timing and instruction sets for 8086 microprocessors, 8086 Assembler, Tutorial



Assembly Language : 8086 Assembler Tutorial Part 12

Assembly Language : 8086 Assembler Tutorial Part 11

Assembly Language : 8086 Assembler Tutorial Part 10

Assembly Language : 8086 Assembler Tutorial Part 9

Assembly Language : 8086 Assembler Tutorial Part 8

Assembly Language : 8086 Assembler Tutorial Part 7

Assembly Language : 8086 Assembler Tutorial Part 6

Assembly Language : 8086 Assembler Tutorial Part 5

Assembly Language : 8086 Assembler Tutorial Part 4

Assembly Language : 8086 Assembler Tutorial Part 3

Assembly Language : 8086 Assembler Tutorial Part 2

Assembly Language : 8086 Assembler Tutorial Part 1

Assembly Language Programming : Complete 8086 instruction sets

Assembly Language Programming : I/O ports - IN/OUT instructions 

Assembly Language programming : Emu8086 Assembler Compiling and MASM / TASM compatibility

Assembly Language - string convert - Lowercase , Uppercase

for programming : the language of Number

Assembly Language - Complete Instruction Set and Instruction Timing of 8086 microprocessors

Assembly Language programming : A list of emulator supported interrupts

Assembly Language Programming : Emu8086 Overview, Using Emulator, Virtual Drives

Assembly Language Programming : All about Memory - Global Memory Table and Custom Memory Map

buy me  a cup of coffee

My Paypal Account is :  ksw.industries@gmail.com

Send me any small amount of money is welcome.
buy me  a cup of coffee

 ___________________________________________


Need More Detail ?   contact me !!


My Paypal Account is :   ksw.industries@gmail.com
buy me  a cup of coffee
Send me any small amount of money is welcome.

___________________________________________


Don't know how to send money ?   Click here for detail about Paypal account.
About PayPal Payment Methods

What type of PayPal accounts is better.
 


Don't have money? OK! Here is another way to get the program.
how to get my program - Free of charge




Saturday, 15 April 2017

Assembly Language : 8086 Assembler Tutorial Part 6

8086 Assembler Tutorial for Beginners (Part 6)

Arithmetic and Logic Instructions

Most Arithmetic and Logic Instructions affect the processor status register (or Flags)



As you may see there are 16 bits in this register, each bit is called a flag and can take a value of 1 or 0.


  • Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example when you add bytes 255 + 1 (result is not in range 0...255). When there is no overflow this flag is set to 0.

  • Zero Flag (ZF) - set to 1 when result is zero. For none zero result this flag is set to 0.

  • Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. Actually this flag take the value of the most significant bit.

  • Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127).

  • Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in result, and to 0 when there is odd number of one bits. Even if result is a word only 8 low bits are analyzed!

  • Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4 bits).

  • Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external devices.

  • Direction Flag (DF) - this flag is used by some instructions to process data chains, when this flag is set to 0 - the processing is done forward, when this flag is set to 1 the processing is done backward.




There are 3 groups of instructions.




First group: ADD, SUB,CMP, AND, TEST, OR, XOR

These types of operands are supported:


REG, memory
memory, REG
REG, REG
memory, immediate
REG, immediate
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.

memory: [BX], [BX+SI+7], variable, etc...

immediate: 5, -24, 3Fh, 10001101b, etc...

After operation between operands, result is always stored in first operand. CMP and TEST instructions affect flags only and do not store a result (these instruction are used to make decisions during program execution).

These instructions affect these flags only:
       CF, ZF, SF, OF, PF, AF.


  • ADD - add second operand to first.
  • SUB - Subtract second operand to first.
  • CMP - Subtract second operand from first for flags only.
  • AND - Logical AND between all bits of two operands. These rules apply:
    1 AND 1 = 1
    1 AND 0 = 0
    0 AND 1 = 0
    0 AND 0 = 0
    As you see we get 1 only when both bits are 1.
  • TEST - The same as AND but for flags only.
  • OR - Logical OR between all bits of two operands. These rules apply:
    1 OR 1 = 1
    1 OR 0 = 1
    0 OR 1 = 1
    0 OR 0 = 0
    As you see we get 1 every time when at least one of the bits is 1.
  • XOR - Logical XOR (exclusive OR) between all bits of two operands. These rules apply:
    1 XOR 1 = 0
    1 XOR 0 = 1
    0 XOR 1 = 1
    0 XOR 0 = 0
    As you see we get 1 every time when bits are different from each other.



Second group: MUL, IMUL, DIV, IDIV

These types of operands are supported:


REG
memory
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.

memory: [BX], [BX+SI+7], variable, etc...

MUL and IMUL instructions affect these flags only:
       CF, OF
When result is over operand size these flags are set to 1, when result fits in operand size these flags are set to 0.

For DIV and IDIV flags are undefined.


  • MUL - Unsigned multiply:
    when operand is a byte:
    AX = AL * operand.
    when operand is a word:
    (DX AX) = AX * operand.
  • IMUL - Signed multiply:
    when operand is a byte:
    AX = AL * operand.
    when operand is a word:
    (DX AX) = AX * operand.
  • DIV - Unsigned divide:
    when operand is a byte:
    AL = AX / operand
    AH = remainder (modulus).
    .
    when operand is a word:
    AX = (DX AX) / operand
    DX = remainder (modulus).
    .
  • IDIV - Signed divide:
    when operand is a byte:
    AL = AX / operand
    AH = remainder (modulus).
    .
    when operand is a word:
    AX = (DX AX) / operand
    DX = remainder (modulus).
    .


Third group: INC, DEC, NOT, NEG

These types of operands are supported:

REG
memory
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.

memory: [BX], [BX+SI+7], variable, etc...

INC, DEC instructions affect these flags only:
       ZF, SF, OF, PF, AF.

NOT instruction does not affect any flags!

NEG instruction affects these flags only:
       CF, ZF, SF, OF, PF, AF.

  • NOT - Reverse each bit of operand.

  • NEG - Make operand negative (two's complement). Actually it reverses each bit of operand and then adds 1 to it. For example 5 will become -5, and -2 will become 2.




  emu8086 is better than NASM, MASM or TASM

Tag: assembly language, assembly instruction, assembly programming, assembly code, assembly guide, emu8086, 8086 microprocessors instruction, instruction sets, instruction sets for 8086, instruction complete set, instruction set complete for 8086, assembly language instruction set, complete 8086 instruction sets microprocessors, complete instruction timing and instruction sets for 8086 microprocessors, 8086 Assembler, Tutorial


Assembly Language : 8086 Assembler Tutorial Part 12

Assembly Language : 8086 Assembler Tutorial Part 11

Assembly Language : 8086 Assembler Tutorial Part 10

Assembly Language : 8086 Assembler Tutorial Part 9

Assembly Language : 8086 Assembler Tutorial Part 8

Assembly Language : 8086 Assembler Tutorial Part 7

Assembly Language : 8086 Assembler Tutorial Part 6

Assembly Language : 8086 Assembler Tutorial Part 5

Assembly Language : 8086 Assembler Tutorial Part 4

Assembly Language : 8086 Assembler Tutorial Part 3

Assembly Language : 8086 Assembler Tutorial Part 2

Assembly Language : 8086 Assembler Tutorial Part 1

Assembly Language Programming : Complete 8086 instruction sets

Assembly Language Programming : I/O ports - IN/OUT instructions 

Assembly Language programming : Emu8086 Assembler Compiling and MASM / TASM compatibility

Assembly Language - string convert - Lowercase , Uppercase

for programming : the language of Number

Assembly Language - Complete Instruction Set and Instruction Timing of 8086 microprocessors

Assembly Language programming : A list of emulator supported interrupts

Assembly Language Programming : Emu8086 Overview, Using Emulator, Virtual Drives

Assembly Language Programming : All about Memory - Global Memory Table and Custom Memory Map

buy me  a cup of coffee

My Paypal Account is :  ksw.industries@gmail.com

Send me any small amount of money is welcome.
buy me  a cup of coffee

 ___________________________________________


Need More Detail ?   contact me !!


My Paypal Account is :   ksw.industries@gmail.com
buy me  a cup of coffee
Send me any small amount of money is welcome.

___________________________________________


Don't know how to send money ?   Click here for detail about Paypal account.
About PayPal Payment Methods

What type of PayPal accounts is better.
 


Don't have money? OK! Here is another way to get the program.
how to get my program - Free of charge




Tuesday, 11 April 2017

Assembly Language : 8086 Assembler Tutorial Part 5

Assembly Language programming : 8086 Assembler Tutorial (Part 5)

Library of common functions - emu8086.inc

To make programming easier there are some common functions that can be included in your program. To make your program use functions defined in other file you should use the INCLUDE directive followed by a file name. Compiler automatically searches for the file in the same folder where the source file is located, and if it cannot find the file there - it searches in Inc folder.

Currently you may not be able to fully understand the contents of the emu8086.inc (located in Inc folder), but it's OK, since you only need to understand what it can do.

To use any of the functions in emu8086.inc you should have the following line in the beginning of your source file:

include 'emu8086.inc'











emu8086.inc defines the following macros:


  • PUTC char - macro with 1 parameter, prints out an ASCII char at current cursor position.
  • GOTOXY col, row - macro with 2 parameters, sets cursor position.
  • PRINT string - macro with 1 parameter, prints out a string.
  • PRINTN string - macro with 1 parameter, prints out a string. The same as PRINT but automatically adds "carriage return" at the end of the string.
  • CURSOROFF - turns off the text cursor.
  • CURSORON - turns on the text cursor.
To use any of the above macros simply type its name somewhere in your code, and if required parameters, for example:


include emu8086.inc

ORG    100h

PRINT 'Hello World!'

GOTOXY 10, 5

PUTC 65           ; 65 - is an ASCII code for 'A'
PUTC 'B'

RET               ; return to operating system.
END               ; directive to stop the compiler.


When compiler process your source code it searches the emu8086.inc file for declarations of the macros and replaces the macro names with real code. Generally macros are relatively small parts of code, frequent use of a macro may make your executable too big (procedures are better for size optimization).




emu8086.inc also defines the following procedures:


  • PRINT_STRING - procedure to print a null terminated string at current cursor position, receives address of string in DS:SI register. To use it declare: DEFINE_PRINT_STRING before END directive.
  • PTHIS - procedure to print a null terminated string at current cursor position (just as PRINT_STRING), but receives address of string from Stack. The ZERO TERMINATED string should be defined just after the CALL instruction. For example:

    CALL PTHIS
    db 'Hello World!', 0

    To use it declare: DEFINE_PTHIS before END directive.
  • GET_STRING - procedure to get a null terminated string from a user, the received string is written to buffer at DS:DI, buffer size should be in DX. Procedure stops the input when 'Enter' is pressed. To use it declare: DEFINE_GET_STRING before END directive.
  • CLEAR_SCREEN - procedure to clear the screen, (done by scrolling entire screen window), and set cursor position to top of it. To use it declare: DEFINE_CLEAR_SCREEN before END directive.
  • SCAN_NUM - procedure that gets the multi-digit SIGNED number from the keyboard, and stores the result in CX register. To use it declare: DEFINE_SCAN_NUM before END directive.
  • PRINT_NUM - procedure that prints a signed number in AX register. To use it declare: DEFINE_PRINT_NUM and DEFINE_PRINT_NUM_UNS before END directive.
  • PRINT_NUM_UNS - procedure that prints out an unsigned number in AX register. To use it declare: DEFINE_PRINT_NUM_UNS before END directive.

To use any of the above procedures you should first declare the function in the bottom of your file (but before END!!), and then use CALL instruction followed by a procedure name. For example:


include 'emu8086.inc'

ORG    100h

LEA    SI, msg1       ; ask for the number
CALL   print_string   ;
CALL   scan_num       ; get number in CX.

MOV    AX, CX         ; copy the number to AX.

; print the following string:
CALL   pthis
DB  13, 10, 'You have entered: ', 0

CALL   print_num      ; print number in AX.

RET                   ; return to operating system.

msg1   DB  'Enter the number: ', 0

DEFINE_SCAN_NUM
DEFINE_PRINT_STRING
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS  ; required for print_num.
DEFINE_PTHIS

END                   ; directive to stop the compiler.


First compiler processes the declarations (these are just regular the macros that are expanded to procedures). When compiler gets to CALL instruction it replaces the procedure name with the address of the code where the procedure is declared. When CALL instruction is executed control is transferred to procedure. This is quite useful, since even if you call the same procedure 100 times in your code you will still have relatively small executable size. Seems complicated, isn't it? That's ok, with the time you will learn more, currently it's required that you understand the basic principle.











http://xyberpast.blogspot.com/2017/04/assembly-language-8086-assembler.html

 emu8086 is better than NASM, MASM or TASM

Tag: assembly language, assembly instruction, assembly programming, assembly code, assembly guide, emu8086, 8086 microprocessors instruction, instruction sets, instruction sets for 8086, instruction complete set, instruction set complete for 8086, assembly language instruction set, complete 8086 instruction sets microprocessors, complete instruction timing and instruction sets for 8086 microprocessors, 8086 Assembler, Tutorial

Assembly Language : 8086 Assembler Tutorial Part 12

Assembly Language : 8086 Assembler Tutorial Part 11

Assembly Language : 8086 Assembler Tutorial Part 10

Assembly Language : 8086 Assembler Tutorial Part 9

Assembly Language : 8086 Assembler Tutorial Part 8

Assembly Language : 8086 Assembler Tutorial Part 7

Assembly Language : 8086 Assembler Tutorial Part 6

Assembly Language : 8086 Assembler Tutorial Part 5

Assembly Language : 8086 Assembler Tutorial Part 4

Assembly Language : 8086 Assembler Tutorial Part 3

Assembly Language : 8086 Assembler Tutorial Part 2

Assembly Language : 8086 Assembler Tutorial Part 1

Assembly Language Programming : Complete 8086 instruction sets

Assembly Language Programming : I/O ports - IN/OUT instructions 

Assembly Language programming : Emu8086 Assembler Compiling and MASM / TASM compatibility

Assembly Language - string convert - Lowercase , Uppercase

for programming : the language of Number

Assembly Language - Complete Instruction Set and Instruction Timing of 8086 microprocessors

Assembly Language programming : A list of emulator supported interrupts

Assembly Language Programming : Emu8086 Overview, Using Emulator, Virtual Drives

Assembly Language Programming : All about Memory - Global Memory Table and Custom Memory Map

buy me  a cup of coffee

My Paypal Account is :  ksw.industries@gmail.com

Send me any small amount of money is welcome.
buy me  a cup of coffee

 ___________________________________________


Need More Detail ?   contact me !!


My Paypal Account is :   ksw.industries@gmail.com
buy me  a cup of coffee
Send me any small amount of money is welcome.

___________________________________________


Don't know how to send money ?   Click here for detail about Paypal account.
About PayPal Payment Methods

What type of PayPal accounts is better.
 


Don't have money? OK! Here is another way to get the program.
how to get my program - Free of charge


Monday, 10 April 2017

Assembly Language Programming : Emu8086 Overview, Using Emulator, Virtual Drives

Everything for learning assembly language in one pack! 

Before Emu8086 I used to program in TASM. I write my assembly language codes and assemble and run them in TASM. You can write your program in any format, whether in TASM, NASM, MASM format, they are all compatible in emu8086. Also, in emu8086, you can see the REAL and ACTUAL steps that an assemble does. It means that you can simulate every interrupts in your program :)


Emu8086 combines an advanced source editor, assembler, disassembler, software emulator (Virtual PC) with debugger, and step by step tutorials.

This program is extremely helpful for those who just begin to study assembly language. It compiles the source code and executes it on emulator step by step.

Visual interface is very easy to work with. You can watch registers, flags and memory while your program executes.

Arithmetic & Logical Unit (ALU) shows the internal work of the central processor unit (CPU).

Emulator runs programs on a Virtual PC, this completely blocks your program from accessing real hardware, such as hard-drives and memory, since your assembly code runs on a virtual machine, this makes debugging much easier.

8086 machine code is fully compatible with all next generations of Intel's micro-processors, including Pentium II and Pentium 4, I'm sure Pentium 5 will support 8086 as well. This makes 8086 code very portable, since it runs both on ancient and on the modern computer systems. Another advantage of 8086 instruction set is that it is much smaller, and thus easier to learn.

Emu8086 has a much easier syntax than any of the major assemblers, but will still generate a program that can be executed on any computer that runs 8086 machine code; a great combination for beginners!

Note: If you don't use Emu8086 to compile the code, you won't be able to step through your actual source code while running it.


Where to start?


  1. Start Emu8086 by selecting its icon from the start menu, or by running Emu8086.exe.

  2. Select "Samples" from "File" menu.

  3. Click [Compile and Emulate] button (or press F5 hot key).

  4. Click [Single Step] button (or press F8 hot key), and watch how the code is being executed.

  5. Try opening other samples, all samples are heavily commented, so it's a great learning tool.

  6. This is the right time to see the tutorials.


Using Emulator


If you want to load your code into the emulator, just click "Emulate" button .
But you can also use emulator to load executables even if you don't have the original source code. Select "Show Emulator" from "Emulator" menu.



Try loading files from "MyBuild" folder. If there are no files in "MyBuild" folder return to source editor, select Samples from File menu, load any sample, compile it and then load into the emulator:



[Single Step] button executes instructions one by one stopping after each instruction.

[Run] button executes instructions one by one with delay set by step delay between instructions.

Double click on register text-boxes opens "Extended Viewer" window with value of that register converted to all possible forms. You can modify the value of the register directly in this window.

Double click on memory list item opens "Extended Viewer" with WORD value loaded from memory list at selected location. Less significant byte is at lower address: LOW BYTE is loaded from selected position and HIGH BYTE from next memory address. You can modify the value of the memory word directly in the "Extended Viewer" window,

You can modify the values of registers on runtime by typing over the existing values.

[Flags] button allows you to view and modify flags on runtime.



Virtual Drives

Emulator supports up to 4 virtual floppy drives. By default there is a FLOPPY_0 file that is an image of a real floppy disk (the size of that file is exactly 1,474,560 bytes).

To add more floppy drives select [Create new floppy drive] from [Virtual Drive] menu. Each time you add a floppy drive emulator creates a FLOPPY_1, FLOPPY_2, and FLOPPY_3 files.
Created floppy disks are images of empty IBM/MS-DOS formatted disk images. Only 4 floppy drives are supported (0..3)!
To delete a floppy drive you should close the emulator, delete the required file manually and restart the emulator.

You can determine the number of attached floppy drives using INT 11h this function returns AX register with BIOS equipment list. Bits 7 and 6 define the number of floppy disk drives (minus 1):

Bits 7-6 of AX:
          00 single floppy disk.
          01 two floppy disks.
          10 three floppy disks.
          11 four floppy disks.
Emulator starts counting attached floppy drives from starting from the first, in case file FLOPPY_1 does not exist it stops the check and ignores FLOPPY_2 and FLOPPY_3 files.

To write and read from floppy drive you can use INT 13h function, see list of supported interrupts for more information.

Ever wanted to write your own operating system?


You can write a boot sector of a virtual floppy via menu in emulator:
[Virtual Drive] -> [Write 512 bytes at 7C00 to Boot Sector]
First you should compile a ".boot" file and load it in emulator (see "micro-os_loader.asm" and "micro-os_kernel.asm" in "Samples" for more info).

Then select [Virtual Drive] -> [Boot from Floppy] menu to boot emulator from a virtual floppy.

Then, if you are curious, you may write the virtual floppy to real floppy and boot your computer from it, I recommend using "RawWrite for Windows" from: http://www.chrysocome.net/rawwrite
(note that "micro-os_loader.asm" is not using MS-DOS compatible boot sector, so it's better to use and empty floppy, although it should be IBM (MS-DOS) formatted).

Compiler directive ORG 7C00h should be added before the code, when computer starts it loads first track of a floppy disk at the address 0000:7C00.
The size of a .BOOT file should be less then 512 bytes (limited by the size of a disk sector).





http://xyberpast.blogspot.com/2017/04/assembly-language-8086-assembler.html

 emu8086 is better than NASM, MASM or TASM

Tag: assembly language, assembly instruction, assembly programming, assembly code, assembly guide, emu8086, 8086 microprocessors instruction, instruction sets, instruction sets for 8086, instruction complete set, instruction set complete for 8086, assembly language instruction set, complete 8086 instruction sets microprocessors, complete instruction timing and instruction sets for 8086 microprocessors, 8086 Assembler, Tutorial


Assembly Language : 8086 Assembler Tutorial Part 12

Assembly Language : 8086 Assembler Tutorial Part 11

Assembly Language : 8086 Assembler Tutorial Part 10

Assembly Language : 8086 Assembler Tutorial Part 9

Assembly Language : 8086 Assembler Tutorial Part 8

Assembly Language : 8086 Assembler Tutorial Part 7

Assembly Language : 8086 Assembler Tutorial Part 6

Assembly Language : 8086 Assembler Tutorial Part 5

Assembly Language : 8086 Assembler Tutorial Part 4

Assembly Language : 8086 Assembler Tutorial Part 3

Assembly Language : 8086 Assembler Tutorial Part 2

Assembly Language : 8086 Assembler Tutorial Part 1

Assembly Language Programming : Complete 8086 instruction sets

Assembly Language Programming : I/O ports - IN/OUT instructions 

Assembly Language programming : Emu8086 Assembler Compiling and MASM / TASM compatibility

Assembly Language - string convert - Lowercase , Uppercase

for programming : the language of Number

Assembly Language - Complete Instruction Set and Instruction Timing of 8086 microprocessors

Assembly Language programming : A list of emulator supported interrupts

Assembly Language Programming : Emu8086 Overview, Using Emulator, Virtual Drives

Assembly Language Programming : All about Memory - Global Memory Table and Custom Memory Map

buy me  a cup of coffee

My Paypal Account is :  ksw.industries@gmail.com

Send me any small amount of money is welcome.
buy me  a cup of coffee

 ___________________________________________


Need More Detail ?   contact me !!


My Paypal Account is :   ksw.industries@gmail.com
buy me  a cup of coffee
Send me any small amount of money is welcome.

___________________________________________


Don't know how to send money ?   Click here for detail about Paypal account.
About PayPal Payment Methods

What type of PayPal accounts is better.
 


Don't have money? OK! Here is another way to get the program.
how to get my program - Free of charge