Monday 26 June 2017

Assembly Language : 8086 Assembler Tutorial Part 11

Assembly Language programming : 8086 Assembler Tutorial (Part 11)

Making your own Operating System


Usually, when a computer starts it will try to load the first 512-byte sector (that's Cylinder 0, Head 0, Sector 1) from any diskette in your A: drive to memory location 0000h:7C00h and give it control. If this fails, the BIOS tries to use the MBR of the first hard drive instead.

This tutorial covers booting up from a floppy drive, the same principles are used to boot from a hard drive. But using a floppy drive has several advantages:

  • You can keep your existing operating system intact (Windows, DOS...).

  • It is easy to modify the boot record of a floppy disk.

Example of a simple floppy disk boot program:


; directive to create BOOT file:
#MAKE_BOOT#

; Boot record is loaded at 0000:7C00,
; so inform compiler to make required
; corrections:
ORG 7C00h

; load message address into SI register:
LEA SI, msg

; teletype function id:
MOV AH, 0Eh

print:   MOV AL, [SI]
         CMP AL, 0
         JZ done
         INT 10h   ; print using teletype.
         INC SI
         JMP print

; wait for 'any key':
done:      MOV AH, 0
           INT 16h


; store magic value at 0040h:0072h:
;   0000h - cold boot.
;   1234h - warm boot.
MOV     AX, 0040h
MOV     DS, AX
MOV     w.[0072h], 0000h ; cold boot.

JMP 0FFFFh:0000h  ; reboot!


new_line EQU 13, 10

msg DB  'Hello This is My First Boot Program!'
    DB  new_line, 'Press any key to reboot', 0


Copy the above example to Emu8086 source editor and press [Compile and Emulate] button. The Emulator automatically loads ".boot" file to 0000h:7C00h.

You can run it just like a regular program, or you can use the Virtual Drive menu to Write 512 bytes at 7C00h to the Boot Sector of a virtual floppy drive (FLOPPY_0 file in Emulator's folder).
After writing your program to the Virtual Floppy Drive, you can select Boot from Floppy from Virtual Drive menu.




If you are curious, you may write the virtual floppy (FLOPPY_0) or ".boot" file to a real floppy disk and boot your computer from it, I recommend using "RawWrite for Windows" from: http://www.chrysocome.net/rawwrite
(recent builds now work under all versions of Windows!)

Note: however, that this .boot file is not an MS-DOS compatible boot sector (it will not allow you to read or write data on this diskette until you format it again), so don't bother writing only this sector to a diskette with data on it. As a matter of fact, if you use any 'raw-write' programs, such at the one listed above, they will erase all of the data anyway. So make sure the diskette you use doesn't contain any important data.





".boot" files are limited to 512 bytes (sector size). If your new Operating System is going to grow over this size, you will need to use a boot program to load data from other sectors. A good example of a tiny Operating System can be found in "Samples" folder as:
micro-os_loader.asm
micro-os_kernel.asm


To create extensions for your Operating System (over 512 bytes), you can use ".bin" files (select "BIN Template" from "File" -> "New" menu).

To write ".bin" file to virtual floppy, select "Write .bin file to floppy..." from "Virtual Drive" menu of emulator:



You can also use this to write ".boot" files.

Sector at:
Cylinder: 0
Head:0
Sector: 1
is the boot sector!



Idealized floppy drive and diskette structure:


For a 1440 kb diskette:


  • Floppy disk has 2 sides, and there are 2 heads; one for each side (0..1), the drive heads move above the surface of the disk on each side.

  • Each side has 80 cylinders (numbered 0..79).

  • Each cylinder has 18 sectors (1..18).

  • Each sector has 512 bytes.

  • Total size of floppy disk is: 2 x 80 x 18 x 512 = 1,474,560 bytes.

To read sectors from floppy drive use INT 13h / AH = 02h.







  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




Monday 19 June 2017

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

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


Global Memory Table

8086 CPU can access up to 1 MB of random access memory (RAM), it is limited by segment/offset construction. Since segment registers (CS, SS, ES, DS) can hold maximum value of 0FFFFh and offset registers (IP, BX, SI, DI, BP, SP) can also hold maximum value of 0FFFFh, the largest logical memory location that we can access is FFFF:FFFF or physical address: 0FFFFh * 10h + 0FFFFh = 10FFEFh = 65535 * 16 + 65535 = 1,114,095 bytes
Modern processors have a larger registers so they have much larger memory area that can be accessed, but the idea is still the same.




Memory Table of Emulator (and typical IBM PC):

Physical address of memory area in HEX Short Description
00000 - 00400 Interrupt vectors. Emulator loads "INT_VECT" file at the physical address 00000h.
00400 - 00500 System information area. We use a trick to set some parameters by loading a tiny last part (21 bytes) of "INT_VECT" in that area (the size of that file is 1,045 or 415h bytes, so when loaded it takes memory from 00000 to 00415h).
This memory block is updated by emulator when configuration changes, see System information area table below .
00500 - A0000 A free memory area. A block of 654,080 bytes. Here you can load your programs.
A0000 - B1000 Video memory for VGA, Monochrome, and other adapters. Not used by emulator!
B1000 - B8000 Reserved. Not used by emulator!
B8000 - C0000 32 KB video memory for Color Graphics Adapter (CGA). Emulator uses this memory area to keep 8 pages of video memory. The Emulator screen can be resized, so less memory is required for each page, although emulator always uses 1000h (4096 bytes) for each page (see INT 10h / AH=05h in the list of supported interrupts).
C0000 - F4000 Reserved.
F4000 - 10FFEF ROM BIOS and extensions. Emulator loads "BIOS_ROM" file at the physical address 0F4000h. Interrupt table points to this memory area to get emulation of interrupt functions.


Interrupt Vector (memory from 00000h to 00400h)

INT number       Address in              Address of
in hex           Interrupt Vector        BIOS sub-program

00               00x4 = 00               F400:0170 - CPU-generated,
                                                     divide error.

04               04x4 = 10               F400:0180 - CPU-generated,
                                                     INTO detected
                                                     overflow.

10               10x4 = 40               F400:0190 - Video functions.

11               11x4 = 44               F400:01D0 - Get BIOS
                                                     equipment list.

12               12x4 = 48               F400:01A0 - Get memory size.

13               13x4 = 4C               F400:01B0 - Disk functions.

15               15x4 = 54               F400:01E0 - BIOS functions.

16               16x4 = 58               F400:01C0 - Keyboard functions.

19               19x4 = 64               FFFF:0000 - Reboot.

1A               1Ax4 = 68               F400:0160 - Time functions.

1E               1Ex4 = 78               F400:AFC7 - Vector of Diskette
                                                     Controller Params.

20               20x4 = 80               F400:0150 - DOS function:
                                                     terminate program.

21               21x4 = 84               F400:0200 - DOS functions.

all others       ??x4 = ??               F400:0100 - The default interupt
                                                     catcher. Prints out
                                                     "Interupt not supported
                                                     yet" message.
A call to BIOS sub-system is disassembled by "BIOS DI" (it doesn't use DI register in any way, it's just because of the way the encoding is done: we are using "FF /7" for such encoding, "FFFFCD10" is used to make emulator to emulate interrupt number 10h).

F400:0100 has this code FFFFCDFF (decoded as INT 255, and error message is generated).




 
System information area (memory from 00400h to 00500h)

Address (hex) Size Description
0040h:0010 WORD BIOS equipment list.

Bit fields for BIOS-detected installed hardware:
Bit(s) Description
 15-14  number of parallel devices.
 13     not supported.
 12     game port installed.
 11-9   number of serial devices.
 8      reserved.
 7-6    number of floppy disk drives (minus 1):
          00 single floppy disk;
          01 two floppy disks;
          10 three floppy disks;
          11 four floppy disks.
 5-4    initial video mode:
          00 EGA,VGA,PGA, or other with on-board video BIOS;
          01 40x25 CGA color;
          10 80x25 CGA color (emulator default);
          11 80x25 mono text.
 3    not supported.
 2    not supported.
 1    math coprocessor installed.
 0    set when booted from floppy (always set by emulator).
This word is also returned in AX by INT 11h.
Default value: 0021h or 0000 0000 0010 0001b
0040h:0013 WORD Kilobytes of contiguous memory starting at absolute address 00000h.
This word is also returned in AX by INT 12h.
This value is set to: 0280h (640KB).
0040h:004A WORD Number of columns on screen.
Default value: 0032h (50 columns).
0040h:004E WORD Current video page start address in video memory (after 0B800:0000).
Default value: 0000h.
0040h:0050 8 WORDs Contains row and column position for the cursors on each of eight video pages.
Default value: 0000h (for all 8 WORDs).
0040h:0062 BYTE Current video page number.
Default value: 00h (first page).
0040h:0084 BYTE Rows on screen minus one.
Default value: 13h (19+1=20 columns).








Custom Memory Map


You can define your own memory map (different from IBM-PC). It is required to create "CUSTOM_MEMORY_MAP.inf" file in the same folder where Emu8086.exe is located. Using the following format add information into that configuration file:

address - filename
...


For example:

0000:0000 - System.bin
F000:0000 - Rom.bin
12AC - Data.dat


Address can be both physical (without ":") or logical, value must be in hexadecimal form. Emulator will look for the file name after the "-" and load it into the memory at the specified address.

Emulator will not update System information area (memory from 00400h to 00500h) if your configuration file has "NO_SYS_INFO" directive (on a separate line). For example:

NO_SYS_INFO
0000:0000 - System.bin
F000:0000 - Rom.bin
12AC - Data.dat


Emulator will allow you to load ".bin" files to any memory address (be careful not to load them over your custom system/data area).

Warning! standard interrupts will not work when you change the memory map, unless you provide your own replacement for them. To disable changes just delete or rename "CUSTOM_MEMORY_MAP.inf" file, and restart the program.









  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