
from http://www3.ntu.edu.sg/home/ehchua/programming/java/DataRepresentation.html :



Last modified: January, 2014
Feedback, comments, corrections, and errata can be sent to Chua Hock-Chuan (ehchua@ntu.edu.sg)
Category Archives: codes
3.31.2014 passing to 4.1.2014 april fool testNASM prologue
; boot.asm
; bin version
; assemble with: nasm -w+all -f bin testNASM.asm -o testNASM.bin -l testNASM.lst > output.txt
; because–whether in jest or in all seriousness–words [“what’s in a name/word. A rose by any other name would smell as sweet.”] that violate Moses’ “10 commandments” [people like to blame by association even though it’s really
; association is not absolute knowledge because it is ultimately knowable only between God and one’s conscience at last: To^nAn was not aware of them the words–and hence could not ordinarily be blamed for them–until neighbors
; [4/3/2014 going with mother and saw mr. and mrs. green ~ able farmers across from dda.’t’s house …] and the Salvation Army suggested it to him and then he is ordinarily blameable by association even though association is no evidence … and anyway To^nAn would be the first
; to admit that he did use a fire thrower on house flies in a most unconscious way …] found their way
; into the programming language [API’s layer] of the operating systems of Microsoft, Apple [not the original Macintosh presided over mainly with Steve Job based on Motorola cpu MacOS 1-9 pre MacOS-X], Cell Phones [android, etc.]
; To^nAn decides to try to write an API programming language layer [Microsoft, Apple, Android, etc. could simply do a “search and replace” all the objectionable words that violate the “10 commandments” and instantly their
; programs would be “10-commandment-conforming”:
; supposedly ye^’n bought a mobile home … here’s a song about the cat Moses … sea of mexico instead of red sea … to escape from vegas if not from egypt … blue cross blue shield black nurse flashes cleopatra eyes 4/2/2014 …
; “Joshua Kadison – Jesse”
; From a phone booth in Vegas, Jesse calls at five am,
;To tell me how she’s tired, of all of them.
;She says, “Baby I’ve been thinkin’ ’bout a trailer by the sea.
;We could goto Mexico, you, the cat, and me.
;We’ll drink Taquilla, and look for seashells, now doesn’t that sound sweet?”
;Oh Jesse, you always do this, everytime I get back on my feet.
;Oh Jesse, paint you pictures, ’bout how it’s gonna be.
;By now I should know better, your dreams are never free.
;But tell me all about, our little trailer by the sea.
;Oh Jesse, you can always sell any dream to me.
;Oh Jesse, you can always sell any dream to me.
;She asked me the cat’s been, I said, “Moses, he’s just fine.
;But used to think about you, all of the time.
;We finally took your pictures, down from off the wall.
;Oh Jesse, how do you always seem to know just when to call?”.
;She says, “Get your sutff together, bring Moses and drive real fast.”
;And I listened to her promise, I swear to God this time it’s gonna last.
;Oh Jesse, paint you pictures, ’bout how it’s gonna be.
;By now I should know better, your dreams are never free.
;But tell me all about, our little trailer by the sea.
;Oh Jesse, you can always sell any dream to me.
;Oh Jesse, you can always sell any dream to me.
;I’ll love in the sunshine, lay you down in the warm, white sand.
;And who know, maybe this time, things wil turn out just the way you planned.
;Oh Jesse, paint you pictures, ’bout how it’s gonna be.
;By now I should know better, your dreams are never free.
;But tell me all about, our little trailer by the sea.
;Oh Jesse, you can always sell any dream to me.
;Oh Jesse, you can always sell any dream to me
; http://youtu.be/upJxt64uRWg
; no new or “golden” technologies must be invented … one uses the same “common” technology in much the same manner that one uses a “common” sun and a “common” rain … indeed, it
; would seem silly to “copyright” the words of Moses’ “10 commandment” …which is essentially all that it would entail … it would seem even more silly to “copyright” the words ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’
; or to expect fame and fortune and gold from the words ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ … http://www.scoutsongs.com/lyrics/onetinsoldier.html… even though in some sense “golden” are those words ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ …]
; that will not violate Moses’ “10 commandments” … [even though it is layered over a layer that disobeys Moses … the Ultimate++ IDE tries to obey Moses … http://www.ultimatepp.org/… without inventing any new technologies … being thus only responsible for its own layer: to each his/her own “added-value” marginal-economic layer/vhd’s
; where vhd’s = virtual hard disk … virtual ~ ghost …: Ultimate++ IDE tries to provide a layer that invents no new technologies but that conforms to Moses “10 commandment” language/vocabulary on top of a layer that violates Moses “10 commandment” language/vocabulary]… or in fact rather an API that is centered on/around [ba` No^.i ba` Ngoa.i’s ddi’ch/dda.m] ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ ….
; there is room for both in the same way that there are seasons of the sun winter, spring, summer, autumn, …
; And she said, hey ramblin’ boy, why don’t you settle down
; 4/4/2014 co^ Be^ telephoned saying she return with Dave Lowe the car to To^nDDi.nh and Die^~m and was invited to stay the night in mother’s room since Ye^’n has returned with Gia Ba?o to stay in the “New York” [Tri.nh Co^ng So+n ca’t bu.i song on SBTN] room and they had banana for breakfast today before returning home to Hawaii or going to China …
; Dave Loggins’ song “Please come to Boston” …. Boston Marathon horror last year … hometown of chu’ Kha … us-europe financial aid to ukraine this year … mr. arsen resemblance interviewed on pbs buddha … dr. scholls [shore: year of the horse, movie giant “that child is an entirely different man that does not want to ride horses but wants to be a doctor”]
; Please come to Boston for the springtime
; I’m stayin’ here with some friends and they’ve got lotsa room
; You can sell your paintings on the sidewalk
; By a café here I hope to be workin’ soon
; Please come to Boston
; She said “No, would you come home to me”
; And she said, “Hey ramblin’ boy now won’t cha settle down
; Boston ain’t your kinda town
; There ain’t no gold and there ain’t nobody like me
; I’m the number one fan of the man from Tennessee” [visit ba’c tha’i ba’c thie^.p who used to have a job in tennessee yesterday: big boy {rain dance with captain america} nino {don’t know how it got this crazy but the children look naked while contemporary/peers seems all right} hanmi {} kimnhung {favorite mo.i/indian: ha~y chi.u kho’ nha^~n na.i la`m thi.t ddi}: ]
; http://www.lyricsmania.com/please_come_to_boston_lyrics_dave_loggins.html
; as pointed out in other notes, each has a distinct responsibility in the same way as distinct zero-footprint path
; to a computer operating system which shines the same light on different responsibilites in the same way as it shines and rains on everyone …
; Should To^nAn failed perhaps because of one threat or another or because of one thing/obstacle or another … because of rush or prolonging or whatnot … because of no force or force … To^nAn would
; be contented [previous year visit to Pleasanton, CA with Whitney Houston and her song “if I fail if I succeed …”] merely in having the “intention” [Plato’s “ideal” … “idea”… 4/7/2014 all neighbors have shown their faces/presences except for Italian/Roman/Y’ Alex Tribuzio;
; and though people jealous of “intention” have often cited out of context or with insufficient explanatory context “the road to hell is paved with good intentions”
; or “Machiavellian end/intention justifies the means” but Rod Stewart sings of his “intentional” heart “… and in my heart you will always be forever young …”] of trying for ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ …
; because everything is
; but a crutch [to^nddi.nh’s stereo: crutchfield electronics] to remind oneself/ourself of the intention ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ …
; And, afterall, when you have achieved the goal of ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’
; you wouldn’t know anyway–because its achievement is characterized by “see/hear/say no evil; have eyes/ears/mouths but as though cannot see/hear/say”– that
; you have achieved ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ … so that it seems like an impossible goal/intention/dream like baiting a horse
; forward by dangling a carrot on a stick in front of it … a goal it could never reached though could be seen/contemplated/intentioned … this goal of
; ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ …
;
;
; “I Write The Songs”
; BARRY MANILOW [David Lowe and co^ Be^ came for U’ Ly` Vie^.t Linh “violet” –“ay, every inch a king/royal” … To^nAn’s purple suit–and Odi–also “ay, every inch a king/royal”– …] LYRICS
; I’ve been alive forever
; And I wrote the very first song
; I put the words and the melodies together
; I am music
; And I write the songs
; [don’t know about manilow, though since it’s universal surely he and everyone would too, tbut to^nan writes ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ …]
; I write the songs that make the whole world sing
; I write the songs of love and special things
; I write the songs that make the young girls cry
; I write the songs, I write the songs
; My home lies deep within you
; And I’ve got my own place in your soul
; Now when I look out through your eyes
; I’m young again, even tho’ I’m very old
; I write the songs that make the whole world sing
; I write the songs of love and special things
; I write the songs that make the young girls cry
; I write the songs, I write the songs
; Oh, my music makes you dance and gives you spirit to take a chance
; And I wrote some rock ‘n roll so you can move
; Music fills your heart, well that’s a real fine place to start
; It’s from me, it’s for you
; It’s from you, it’s for me
; It’s a worldwide symphony
; I write the songs that make the whole world sing
; I write the songs of love and special things
; I write the songs that make the young girls cry
; I write the songs, I write the songs
; I write the songs that make the whole world sing
; I write the songs of love and special things
; I write the songs that make the young girls cry
; I write the songs, I write the songs
; I am music and I write the songs
;Thanks to robin for correcting these lyrics.
;Writer(s): Bruce Johnston
; Copyright: Artists-music Inc.
;http://www.azlyrics.com/lyrics/barrymanilow/iwritethesongs.html
; song “I hope when you decide, kindness will be your guide …”:
; “I did not program you, you program you: cha me. sinh con tro+`i sinh ti’nh/compute/program/ddi.nh:
; I program/vote/ba^`u{di` ba co^ Die^~m’s pregnancy}/wish/love/aim/nail/ddi.nh ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’, and
; Everything/All/Allah/Nature/God programs/votes/ba^`u{di` ba co^ die^~m’s pregnancy}/wishes/loves/aims/nails/ddi.nh ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’, and
; the rest, what’s in between God and I is you is up to you … hopefully you too will program along with God and I for
; ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ ….
; 3/31/2014: supposedly Mr. Le^~ reports Ni Su+ Vie^n Lu+o+ng is supposedly staying in the hospital possibly for tai bie^’n ma.ch na~o …
; Ni Su+ Vie^n Lu+o+ng is associated with striking compassion into To^nan’s heart …
; To^n An does not remember exactly but perhaps she was present when the maid–co^ be^ said con co^ Va^n was main chef
; instead of kitchen helper or sous chef as ba’c Ca^`n said–was cutting chicken throat [the birds, specifically the
; doves, Hitchcock movie “The Birds”, that came to our house to be fed by To^nAn when ba` Ngoa.i was here were
; supposedly to remind To^nAn that mother had chicken noodle soup–Dave Lowe said he likes chicken porridge–when
; she was pregnant with To^nAn …: Devadatta would violate Moses’ “10 commandments” but the Buddha would un-violate it … again there is room
; for both violation and un-violation of Moses “10 commandments” even as there are seasons of the sun, winter, spring, summer, autumn …
; as Ecclesiastes would say … “there is a time for un-Moses and a time for Moses …for Noble Truth of Suffering and Noble Truth of Wellness …” …
; co’ lu’c khu`ng-me^-kho^ng-ti?nh co’ lu’c ti?nh/normal …] in front of To^nAn for the whole family’s supper [SBTN reporter Va.n Ly’ would
; say that no one is singly [unless that one is one’s self: because blaming everyone is equivalent to blaming one’s self] responsible for anyone’s
; death because each death is caused/programmed by va.n ly’ by all/Allah/God by
; everyone by every/all reasons–in particular by/because of “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”]
; before she becomes a buddhist nun …
; shortly before she becomes a buddhist nun and ever after she took to^nan to vie^.n ho’a dda.o or some such to teach him to obey/observe [obeah in movie
; “The wide Sargasso Sea” … “Tua^’n [the cha`m or champa is associated with Hindu temples {even though it has been compared to So+n Tinh Thu?y Tinh, Johny-come-lately Christians and Muslims are welcomed … cha`m/champa and malaysia and indonesia ..}: tu a^’n ddo^. … try india…] tra`ng trai nu+o+’c Vie^.t” was a
; novel in ba’c Tue^.’s library that To^nAn did not have time to borrow and read
; because we have to immigrate to the United States: jamaican wedding of Odi and U’ Ly` with lots of people with British appearance: movie “do the right thing” … to^n ddi.nh and dave lowe or aunts said something about “… fever” … movie “jungle fever” viewed together with “do the right thing”] the Bible’s “10 commandments” to “free” tha? the animals … fishes and birds ….
; between I and God, you are “free” because it’s up to you what you do/program/vote/figure/wish/love/aim in between ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’
; and ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ … co^ Hie^n telephoned after Mr. Le^~ telephoned …
; Because of the “free” clause in “I only fix the boundary condition [to use the terminology of differential equations; 4/3/2014 SBTN Die^.u Quye^n, supposedly a math teacher, says “Happy Birthday” to her hubby, Tru’c Ho^`, … ho^` ~ ca’o ~ defer ~ boundary/wall/gia …] ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ and God only fixes the boundary condition ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’,
; and because what you do–including what you do to me and to God–in between these boundary conditions of ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ is up to you and you alone,
; I and God accepted–“que? ca`n” father depending on Mr. Le^~ thus freeing To^nAn from any dde do.a threats … 4/2/2014 father said something suggesting he is
; ba` no^.i ddi’ch and therefore has he has said ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’–before hand all the possibly bad things possibly good things that you might “freely” do to me [including turning me kho^ng ti?nh from ti?nh or turning any intentions of mine upside down inside out including–not that it can be turned upside down– the intention ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’] and to God in between my and God’s boundary conditions of
; ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ …
; 3/31/2014 To^n DDu+’c telephoned after To^n DDi.nh telephoned after anh Huy telephoned about Nguye^n’s child becoming a doctor and getting married in los angeles, california or las vegas
; the Supreme’s song “Why don’t you be a man about it
;And set me free? (Ooh-ooh-ooh)
; [u’ ly`’s husband odi [President Obama scheduled to be in Ann Arbor 4/3/2014] was ta`o tha’o [“tao xuo^’ng tha’o go+~ “free” he^’t mo.i ra(‘c ro^’i cho ca’c ngu+o+i va` la`m ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well'”]
; at “bi`nh minh qua’n”: he offered to^nan to serve to^nan soup and did so, but to^n an saw that there was a bowl of soup someone –perhaps to^n ddi.nh–had made right by him and so replied “oh seems that I have soup, please have that one for yourself”, so odi retrieved
; the bowl of soup he served to^nan and have it himself … it’s sort of like jerk but not jerk not jerk but jerk ga^`n bu`n ma` cha(?ng ho^i tanh mu`i bu`n … transaction of … a bowl of soup … that becomes the boundary condition for all other transactions… something
; seems to have been exchanged but it was not in fact exchanged…to^nan recalls how malcolm x was “not the cheating kind” … so “children”/”adults”/”boys and girls” go ahead and have your sweets and eat it too … go ahead and have your [“love with no committment” … John Mellencamp’s song “Paper on Fire”] fun …]
;Now, you don’t care a thing about me
;You’re just using me (Ooh-ooh-ooh)
;Go on, get out, get out of my life
;And let me sleep at night (Ooh-ooh-ooh)
;’Cause you don’t really love me
;You just keep me hangin’ on ” http://www.azlyrics.com/lyrics/supremes/youkeepmehanginon.html
; Eternity [“no man is an island” John Donne] for everyone means everyone could only have the bond/freedom/love at best of the [“see/hear/say no evil”] Middle Path of Biblical “in the image”
; in Eternity, each sets the [mathematical] “boundary condition” [see “bound” instruction below …. yesterday 4/1/2014: orange man by paul moody’s former house …
; “The Voice”
; moody blues
;Won’t you take me back to school [gia ba?o wanting to go back, or rather to start/go, to school]
; I need to learn the golden rule [ghen ty. or chi? cho?–imitation is the sincerest form of flattery 4/4/2014 Inside Edition James Frankel life imitates art–or wanting to be taught by the one you’re jealous of … same …]
; Won’t you lay it on the line
; I need to hear it just one more time
; Oh won’t you tell me again
; Can you feel it
; Won’t you tell me again
; Tonight
; Each and every heart it seems
; Is bounded [c.f. cpu instruction “bound” below] by a world of dreams
; Each and every rising sun
; Is greeted by a lonely one
; Oh won’t you tell me again
; Can you feel it
; Oh won’t you tell me again
; Tonight
; http://www.azlyrics.com/lyrics/moodyblues/thevoice.html
; today 4/2/2014: co^ Be^ telephoned for To^nDDi.nh’s telephoned to inquire
; after the whereabout of mathematician David Lowe who is visiting his daughter in Sacramento–the anthropology professor Rappaport is
; big on “sacraments” and on Gregory Bateson … a doll-phi-n of a girl nurse came today for Blue Cross Blue Shield to
; inquire after mother and father health and have a picture of all of us for her brother who marries a Vietnamese girl and have
; two children “we’re close enough to have children” … looking for passage from Gregory Bateson … movie “The book thief” resembling Anne Frank was on
; our flight home from California … that says we should make peace
; with Germany … the SBTN TV says “you bi. pha.t” … kho^ng ti`m tha^’y ddu+o+.c no’ … that passage …not remembering kho^ng nho+’ …
; liquor store guy suggestive of ba’c Tue^. trai came out and threw a cigarette butt at To^nAn’s focus car as we drove passed him … cho pha’t lu+?a/minh … while
; woman tending roasted chicken was dancing and woman suggestive of Mrs. Alicia Renfrew at Sam’s Club turned on personal heater at Sam’s Club … representing sunshine … also Steve Job and
; the “greens” neighbors and people wearing green/blue at Sam’s Club representing farmers … tomorrow mother will go to sinai grace hospital near adult independence place near Ford Motor Co.
; in Dearborn tomorrow which would summarizes note 3.21.2014 as well as summarizing ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ ….] or bonding/freedom boundaries for the others so that each
; can live together eternally with the others by staying in each “zero-footprint path” …
;;from NASM manual:
; The BITS directive specifies whether NASM should generate code designed to run on a processor operating in 16-bit mode, 32-bit mode or 64-bit mode.
; You do not need to specify BITS 32 merely in order to use 32-bit instructions in a 16-bit DOS program; if you do, the assembler will generate incorrect code because it will be writing code targeted at a 32-bit platform, to be run on a 16-bit one:
; When NASM is in BITS 16 mode, instructions which use 32-bit data are prefixed with an 0x66 byte, and those referring to 32-bit addresses have an 0x67 prefix. In BITS 32 mode, the reverse is true: 32-bit instructions require no prefixes, whereas instructions using 16-bit data need an 0x66 and those working on 16-bit addresses need an 0x67.
; When NASM is in BITS 64 mode, most instructions operate the same as they do for BITS 32 mode.
[BITS 16]
; from the Programmer’s Reference Manual
;The segment containing the currently executing sequence of instructions is known as the current code segment;
;it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using
;as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment
;control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.
;The instruction pointer register (EIP) contains the offset address, relative to the start of the current code
;segment, of the next sequential instruction to be executed. The instruction pointer is not directly visible
;to the programmer; it is controlled implicitly by control-transfer instructions, interrupts, and exceptions.
;As Figure 2-9 shows, the low-order 16 bits of EIP is named IP and can be used by the processor as a unit.
;This feature is useful when executing instructions designed for the 8086 and 80286 processors.
; from http://wiki.osdev.org/Babystep2:
; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
; of segment and offset that point to the same address.
; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
; of segment and offset that point to the same address. For instance, some say that the bootloader is is loaded at 0000:7C00,
; while others say 07C0:0000. This is in fact the same address: 16 * 0x0000 + 0x7C00 = 16 * 0x07C0 + 0x0000 = 0x7C00.
; It doesn’t matter if you use 0000:7c00 or 07c0:0000, but if you use ORG you need to be aware of what’s happening
; from http://www.supernovah.com/Tutorials/BootSector2.php:
;The BIOS does not load the boot sector to a random spot in memory. The BIOS will always load the boot sector starting at the memory location 0x7C00.
; from http://www.supernovah.com/Tutorials/BootSector2.php
;As stated earlier, we cannot be sure if the BIOS set us up with the starting address of 0x7C0:0x0 or 0x0:0x7C00.
;We will use the second segment offset pair to execute our boot sector so we know for sure how the CPU will access
;our code. To do this, our very first instruction will be a far jump that simply jumps to the next instruction.
;The trick is, if we specify a segment, even if it is 0x0, the jmp will be a far jump and the CS register will be
;loaded with the value 0x0 and the IP register will be loaded with the address of the next instruction to be
;executed.
;[BITS 16]
;[ORG 0x7C00]
;jmp 0x0:Start
;Start:
; This code will set the CS segment to 0x0, set the IP register to the the very next instruction which will be slightly past 0x7C00, ….
; universal-loop
; {
; start-ORG-nguye^n-thu?y [4/2/2014 woman at Sam’s Club moved near woman resembling thi’m hoa`ng]: maintain-gi`n-giu+~ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // in “gia ba?o”, “ba?o” ~ maintain as in “ba?o thu?/to^`n” …
; try/if ;// tin messages …. the try/if is the “gia” of “gia ba?o” …
; maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH [co^ Be^’s leg etc.] va`… ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // the message “stack” is loaded or push-pop with messages …; // push-and-pop-or-sent-and-receive (&messageNEW-hay-tinLA`NH); // tin and shakespeare’s version of “all roads lead to rome”: “doubt thou the stars are fire doubt truth to be a liar but never doubt I loved ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well'”: 1/19/2014 Sunday Service … Gospel ~ Good News Tin La\nh …”Gia Ba?o”: the “gia” attempts to reach an agreement with the “ba?o” …// salinger on internet news: push/pop/create stack/heap by an expansion assignment (“muo^n loa`i” <= "muo^n loa`i va` messageA va` messageB va` messageC va` ….")
; ;catch/else ;// unmaintainable tin/messages or kho' tin hay kho^ng tin no messages … SBTN Uye^n Thi. commercial for MBR [master boot record] "kho' tin nhu+ng co' tha^.t …"
; ; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n ("muo^n loa`i ddu+o+.c so^'ng la^u bi`nh thu+o+`ng; everyone live long and well");
; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n ("muo^n loa`i ddu+o+.c so^'ng la^u bi`nh thu+o+`ng; everyone live long and well");
; }
; irish-catholic Pat Benatar song "heartbreaker, dreammaker, don't you mess around with me …" ….
; perhaps "there's beggary in a love that can be reckoned" when love is unconditional–gia ba?o chu' hoa`ng to^n an hoa`ng phi hu`ng and 10 commandments–but
; the ten commandments say there's a love that's conditional … and the 10 commandments describe the limits or conditions of that love …
; from http://wiki.osdev.org/Babystep2:
;some say that the bootloader is loaded at [metaphorical address] 0000:7C00, while others say 07C0:0000.
;This is in fact the same [real] address: 16 * 0x0000 + 0x7C00 = 16 * 0x07C0 + 0x0000 = 0x7C00.
;%define ORIGIN ; ….. comment this out to use "org 0" instead of "org 0x07C0" …
; test segment:offset scheme
;%assign ORIGIN 0x0
;%assign ORIGIN 0x7c00
%assign ORIGIN 0x7990 ; 3/6/2014 home alone with mother …
;%ifdef ORIGIN
%if ORIGIN = 0x7c00
[ORG 0x7c00]
%define PROGRAMSEGMENT 0x0
;segment .text align=16
; segment:offset … ds:offset or cs:offset … 0:offset-from-0x7COO … that is, labels in code following is addressed as 0:0x7C00+offset-from-start-of-file
;Following code will set the CS segment to 0x0, set the IP register to the the very next instruction which will be slightly past 0x7C00, ….
jmp 0x0:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
;%else ;
%elif ORIGIN = 0x0
[ORG 0]
%define PROGRAMSEGMENT 0x07C0
;segment .text align=16
; segment:offset … ds:offset or cs:offset … 0x07C0:offset-from-0 … that is, labels in the code following is addressed as 0x07C0:0+offset-from-start-of-file
;Following code will set the CS segment to 0x07C0, set the IP register to the the very next instruction which will be slightly past 0x0, ….
jmp 0x07C0:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; from http://wiki.osdev.org/Babystep2:
; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
; of segment and offset that point to the same address.
; (0x07c00 – 0x07cf) / 0x10 = (7431) / 0x10 = 743.1
; (0x07c00 – 0x03e7) / 0x10 =
; (0x07c00 – 0x7990) / 0x10 = 0x0270 / 0x10 = 0x0027
; 31744 – 31120
%elif ORIGIN = 0x7990 ; grateful for hexadecimal conversion from http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html and hex calculator from http://www.miniwebtool.com/hex-calculator/?number1=270&operate=1&number2=7990
[ORG 0x7990]
%define PROGRAMSEGMENT 0x0027
;segment .text align=16
; segment:offset … ds:offset or cs:offset … 0x0027:offset-from-0x7990 … that is, labels in code following is addressed as 0:0x7990+offset-from-start-of-file
;Following code will set the CS segment to 0x0027, set the IP register to the the very next instruction which will be slightly past 0x7990, ….
jmp 0x0027:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
;%endif ; ORIGIN
%endif; ORIGIN
;%ifdef ORIGIN
%if ORIGIN = 0x7c00
%define MEMORYSEGMENTREALLOWBOUND 0x7C00 ; 31744
;%else
%elif ORIGIN = 0x0
%define MEMORYSEGMENTREALLOWBOUND 0x0000 ; 0
%elif ORIGIN = 0x7990 ; grateful for hexadecimal conversion from http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html and hex calculator from http://www.miniwebtool.com/hex-calculator/?number1=270&operate=1&number2=7990
%define MEMORYSEGMENTREALLOWBOUND 0x0027 ; 39
%endif ; ORIGIN
%define SEGMENTSIZE 512
%define MEMORYSEGMENTREALUPPERBOUND MEMORYSEGMENTREALLOWBOUND + SEGMENTSIZE
; there was a program on the internet [e.g. http://frz.ir/dl/tuts/8086_Assembly.pdf%5D written entirely
; using NASM pseudo-op "db". For example,
; dw 0xfeeb will generate the same bit patterns as jmp $ in the binary file. The interrupt table and stacksegment and datasegment with pseudo-opcodes db, dw etc. here
; was "jmp-ed" over …
%define TRYIVT ; try out ivt codes … comment this out to exclude ivt codes
%ifdef TRYIVT
; interrupts are a type of messages "muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^'ng la^u bi`nh thu+o+`ng; everyone live long and well"
; and the interrupt table [of outgoing becauses/answers/responses {do tha'i … } to incoming messages] is placed as close to the origin nguye^n thu?y 0x0:0x0 as possible with/by the BIOS
; girl immitating the suprememes pointing fingers on our trip to san francisco:
; I know, I know you must follow the sun
;Wherever it leads
;But remember
;If you should fall short of your desires
;Remember life holds for you one guarantee
;You'll always have me
; And if you should miss my lovin
;One of these old days
;If you should ever miss the arms
;That used to hold you so close, or the lips
;That used to touch you so tenderly
;Just remember what I told you
;The day I set you free
;
;Ain't no mountain high enough
;Ain't no valley low enough
;Ain't no river wild enough
;To keep me from you
; http://youtu.be/VqW2XigtDEU
; 3/22/2014 ye^'n returned, chu' ha^n telephoned after vu~ng ta^`u restaurant Glady Knights and the Pip–a couple of days ago van wilder II peep/pip/nhi`nh/ and Charles dickens Great Expectation pip–Midnight Train to Georgia: note 2.9.2014 porn left la for the desert of las vegas …
; universal-loop
; {
; start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~ba?o-to^`n ("muo^n loa`i ddu+o+.c so^'ng la^u bi`nh thu+o+`ng; everyone live long and well"); // in "gia ba?o", "ba?o" ~ maintain as in "ba?o thu?/to^`n" …
; try/if ;// tin messages …. the try/if is the "gia" of "gia ba?o" …
; maintain-gi`n-giu+~-ba?o-to^`n ("muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^'ng la^u bi`nh thu+o+`ng; everyone live long and well"); // the message "stack" is loaded or push-pop with messages …; // push-and-pop-or-sent-and-receive (&messageNEW-hay-tinLA`NH); // tin and shakespeare's version of "all roads lead to rome": "doubt thou the stars are fire doubt truth to be a liar but never doubt I loved 'muo^n loa`i ddu+o+.c so^'ng la^u bi`nh thu+o+`ng; everyone live long and well'": 1/19/2014 Sunday Service … Gospel ~ Good News Tin La\nh …"Gia Ba?o": the "gia" attempts to reach an agreement with the "ba?o" …// salinger on internet news: push/pop/create stack/heap by an expansion assignment ("muo^n loa`i" MEMORYSEGMENTREALLOWBOUND) \
& (REALADDRESS(SEGMENTADDRESSTOVERIFY,OFFSETADDRESSTOVERIFY) < MEMORYSEGMENTREALUPPERBOUND)
; generate some virtual segment:offset address for use with a real address …
; TO DO: align the generated addresses to "natural" byte boundaries …
; %define GENERATESEGMENTADDRESS(REALADDRESSNO, &GENSEGMENTNO, &GENOFFSETNO) …………….
; %define GENERATEVIRTUALSEGMENTADDRESS(REALADDRESSNO, VIRTUALOFFSETADDRESSINPUT) (REALADDRESSNO – VIRTUALOFFSETADDRESSINPUT)/16
; %define GENERATEOFFSETNO(REALADDRESSNO, VIRTUALSEGMENTADDRESSINPUT) (REALADDRESSNO – VIRTUALSEGMENTADDRESSINPUT * 16)
; from http://geezer.osdevbrasil.net/johnfine/segments.htm:
;The way it really works
; Each segment register is really four registers: A selector register
;A base register
;A limit register
;An attribute register
;
;In all modes, every access to memory that uses a segment register uses the base, limit, and attribute portions of the segment register and does not use the selector portion.
;Every direct access to a segment register (PUSHing it on the stack, MOVing it to a general register etc.) uses only the selector portion. The base, limit, and attribute portions are either very hard or impossible to read (depending on CPU type). They are often called the "hidden" part of the segment register because they are so hard to read.
;Intel documentation refers to the hidden part of the segment register as a "descriptor cache". This name obscures the actual behavior of the "hidden" part.
; In real mode (or V86 mode), when you write any 16-bit value to a segment register, the value you write goes into the selector and 16 times that value goes into the base. The limit and attribute are not changed.
;In pmode, any write to a segment register causes a descriptor to be fetched from the GDT or LDT and unpacked into the base, limit and attribute portion of the segment register. (Special exception for the NULL Selector).
;When the CPU switchs between real mode and pmode, the segment registers do not automatically change. The selectors still contain the exact bit pattern that was loaded into them in the previous mode. The hidden parts still contain the values they contained before, so the segment registers can still be used to access whatever segments they refered to before the switch.
;Writes to a segment register
;When I refer to "writing to a segment register", I mean any action that puts a 16-bit value into a segment register.
;The obvious example is something like:
; MOV DS,AX
;However the same rules apply to many other situations, including: POP to a segment register.
;FAR JMP or CALL puts a value in CS.
;IRET or FAR RET puts a value in CS.
;Both hardware and software interrupts put a value in CS.
;A ring transition puts a value in both SS and CS.
;A task switch loads all the segment registers from a TSS.
; from the Programmer's Reference Manual
;The segment containing the currently executing sequence of instructions is known as the current code segment;
;it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using
;as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment
;control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.
main:
; to use the stack, use "call" and "ret" instead of "jmp"
;jmp screensetup ; or just let the program flows, without the jmp, to instructions that follow
; call screensetup
call word screensetup
; call clearscreenpixels
call word clearscreenpixels
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; mov [spprevious], SP
;bound SP, [stacklowerbound + 4 + 4 ;
;bound SP, [stacklowerboundaddress]
; 3/29/2014 wedding of u' ly`: co^ Tu' complained that DDu`m and his Mie^n wife don't say hello kho^ng cha`o …
%define SAYHELLO 1
%ifdef SAYHELLO
; call sayhello
call word sayhello
%endif ; SAYHELLO
; mov [spnew], SP
; mov word [spcounter + 2 * 1], spprevious – spnew
; To^n DDi.nh said "you know that they're always trying to 'push the envelope' ….": the stack and heap are sort of "envelopes" that programs "push" …
; http://forums.devshed.com/programming-42/asm-bound-instruction-handling-interrupt-5-a-107376.html
; SAFEWAY grocery …
%macro SAFECALL 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safecallinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
call %1
%endmacro
%macro SAFEPUSH 1
;;stacklowerbound dw 0 ; equ stacksegment
;;stackupperbound dw 0 ; equ stacktop
;;mov ax, stacksegment
;;mov [stacklowerbound], ax
;;mov ax, stacktop
;;mov [stackupperbound], ax
; bound SP, [stacklowerbound]
; mov BP, SP
; bound BP, [stacklowerbound]
bound BP, stacklowerbound
push %1
; cmp SP, stacksegment
; jl safepushinterrupt
; safepushinterrupt int 5
; bound SP, stacklowerbound + 4 + 4 ;
;; mov byte [ES:600],'a'
;; cmp dword [wasinterrupted], 1
;; je returnfromservicingpush
;; mov byte [ES:602],'b'
;; cmp SP, stacksegment + 10
;cmp SP, stacksegment
;jb safepushinterrupt ; unsigned transfer
;jl safepushinterrupt ; signed transfer
;ja safepushinterrupt ; unsigned transfer
;jg safepushinterrupt ; signed transfer
;; ja safetopush
;; mov byte [ES:604],'c'
;; mov dword [wasinterrupted], 1
;; int 5
;; jmp returnfromservicingpush
;;safetopush:
;; mov byte [ES:606],'d'
;; add dword [numberofpushrequired], 1
;; push %1
;;returnfromservicingpush:
;; mov byte [ES:610],'e'
;; nop ; no operation … can be commented out …
;safepushinterrupt: int 5
; from https://courses.engr.illinois.edu/ece390/books/artofasm/CH06/CH06-5.html#HEADING5-171
; cmp reg, LowerBound
; jl OutOfBounds
; cmp reg, UpperBound
; jg OutOfBounds
;On the 80486 and Pentium/586 chips, the sequence above only requires four clock cycles assuming you can use the immediate addressing mode and the branches are not taken; the bound instruction requires 7-8 clock cycles under similar circumstances and also assuming the memory operands are in the cache.
%endmacro
%macro SAFEPOP 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safepopinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
pop %1
%endmacro
%macro SAFERET 1
; cmp SP, stacksegment
; jl safecallinterrupt
; saferetinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
ret %1
%endmacro
; from http://www.mactech.com/macintosh-c/classic-chap01-1.html
; Macintosh Protection mechanism for the stack: "… every sixtieth of a second an Operating System task checks whether the stack has moved into the heap. If it has, the task, known as the stack sniffer, generates a system error …"
; Intel implements push-pop-able stack data structures such as IDT, GDT etc. defining limits for protection purposes …
; from Programmer's Reference Manual
;6.2 Overview of 80386 Protection Mechanisms
;Protection in the 80386 has five aspects: 1. Type checking
;2. Limit checking
;3. Restriction of addressable domain
;4. Restriction of procedure entry points
;5. Restriction of instruction set
;The protection hardware of the 80386 is an integral part of the memory management hardware. Protection applies both to segment translation and to page translation.
;Each reference to memory is checked by the hardware to verify that it satisfies the protection criteria. All these checks are made before the memory cycle is started; any violation prevents that cycle from starting and results in an exception. Since the checks are performed concurrently with address formation, there is no performance penalty.
;Invalid attempts to access memory result in an exception. Refer to Chapter 9 for an explanation of the exception mechanism . The present chapter defines the protection violations that lead to exceptions.
;The concept of "privilege" is central to several aspects of protection (numbers 3, 4, and 5 in the preceeding list). Applied to procedures, privilege is the degree to which the procedure can be trusted not to make a mistake that might affect other procedures or data. Applied to data, privilege is the degree of protection that a data structure should have from less trusted procedures.
;The concept of privilege applies both to segment protection and to page protection.
%ifdef TRYIVT
call changeivt.loadorgbiosivtwithbiosivt
call changeivt.loadivtwithbiosivt
;call changeivt.loadivtwithorgbiosivt
;Setting:
;mov ax, [intnum*4] ; offset
;mov ax [intnum*4+2] ; segment
; pbs "peg and cat" …. suggestively similar "peg and cat" bedding at baby r us 3/13/2014
; substitute custom interrupt numbers 5 and 9 into new ivt table created by cloning from original BIOS ivt table: neighbor dude with custom truck 3/13/2014
call changeivt.insertcustominterruptsintoivt
call changeivt.setivt
; test custom interrupt numbers 5 and 9 … here …
;;int 5 ; manual interrupt
;;int 9 ; manual interrupt
; test safe stack calls SAFECALLS's with int 5 here ………
; ………
;stacklowerbound dw 0 ; equ stacksegment
;stackupperbound dw 0 ; equ stacktop
mov ax, stacksegment + 20 + 1
mov [stacklowerbound], ax
mov [boundlowerbound], ax
mov ax, stacktop + 1
mov [stackupperbound], ax
mov [boundupperbound], ax
;%define TESTBOUNDINSTRUCTION
%ifdef TESTBOUNDINSTRUCTION
;test the "bound" instruction:
mov ax, 10
mov [boundupperbound], ax
mov ax, 7
mov [boundlowerbound], ax
mov ax, 3
bound ax, [boundlowerbound]
; bound ax, stacklowerbound
hlt
; from Programmer's Reference Manual
; HALT stops instruction execution and places the 80386 in a HALT state. An enabled interrupt, NMI, or a reset will resume execution. If an interrupt (including NMI) is used to resume execution after HLT, the saved CS:IP (or CS:EIP) value points to the instruction following HLT.
%endif ; TESTBOUNDINSTRUCTION
;; xor cx, cx
;mov cx, 64 ; 64
;; mov cx, stacksize
;;stackoverloadloop:
;; ;push ' '
;; add byte [numberofpushrequired], 1
;SAFEPUSH ' '
;; bound SP, [stacklowerbound]
;; cmp SP, [stacklowerbound]
;; jg safetopush
;int 5
;; jmp finishtestinterrupt5
;; safetopush: push word ' '
;; safetopush: nop
;; cmp dword [interrupt5count], 0
;; jg finishtestinterrupt5
;; loop stackoverloadloop
;;finishtestinterrupt5:
;; nop
xor cx, cx
;mov cx, 64 ; 64
mov cx, stacksize
stackoverloadloop:
mov BP, SP
;;mov [stackpointer], SP ; SP ~ (stacktop – amount that have been pushed)
; mov bx, sp ; sp ~ stacktop – amount that have been pushed
;mov BL, [BP]
;cmp BL, [stacklowerbound]
;%define WHATISBP0
%ifdef WHATISBP0
cmp BP, 0
jne bpisnotzero
bpiszero:
mov byte [ES:360], '0'
jmp donecomparingbp
bpisnotzero:
cmp BP, 0
jl bpislessthanzero
mov byte [ES:362], 'G'
jmp donecomparingbp
bpislessthanzero:
mov byte [ES:364], 'L'
jmp donecomparingbp
donecomparingbp:
nop
%endif ; WHATISBP0
cmp BP, stacksegment + 20 ; stacklowerbound
;;bound BL, [stacklowerbound]
jg safetopush
; 4/2/2014: SBTN ba?o cha^u is in flower on black while die^.u quye^n is tulip colors: San Jose calendar for this month says "nothing is too difficult for those with a will":
; 4/3/2014: mother is going to sinai grace hospital to have a cancer test [a test of the conditional/unconditional bound/will/love of God of "muo^n loa`i ddu+o+.c so^'ng la^u bi`nh thu+o+`ng; everyone live long and well" …] today ….
;%define TESTBOUNDMANUALLY
%ifdef TESTBOUNDMANUALLY
int 5
%else
; 4/5/2014 seems that internally "bound" instruction uses "signed" comparisons before calling int 5 … so …
; from Programmer's Reference Manual: "BOUND ensures that a signed array index is within the limits …"
;bound BP, [stacklowerbound] ; valid for NASM
bound BP, [boundlowerbound] ; valid for NASM
;bound ax, stacklowerbound ; invalid for NASM
;bound ax, bx ; invalid for NASM, of course
%endif ; TESTBOUNDMANUALLY
jmp finishtestinterrupt5
safetopush:
add byte [numberofpushrequired], 1
%ifdef TESTBOUNDMANUALLY
push ' '
%else
push ' '
;SAFEPUSH ' '
; bound BP, [stacklowerbound]
; from Programmer's Reference Manual
; The BOUND instruction includes two operands. The first operand specifies the register being tested. The second operand contains the effective relative address of the two signed BOUND limit values. The BOUND instruction assumes that the upper limit and lower limit are in adjacent memory locations. These limit values cannot be register operands; if they are, an invalid opcode exception occurs.
;BOUND is useful for checking array bounds before using a new index value to access an element within the array. BOUND provides a simple way to check the value of an index register before the program overwrites information in a location beyond the limit of the array.
;The block of memory that specifies the lower and upper limits of an array might typically reside just before the array itself. This makes the array bounds accessible at a constant offset from the beginning of the array. Because the address of the array will already be present in a register, this practice avoids extra calculations to obtain the effective address of the array bounds.
;The upper and lower limit values may each be a word or a doubleword.
;IF (LeftSRC [RightSRC + OperandSize/8])
; (* Under lower bound or over upper bound *)
;THEN Interrupt 5;
;FI;
; BOUND ensures that a signed array index is within the limits specified by a block of memory consisting of an upper and a lower bound. Each bound uses one word for an operand-size attribute of 16 bits and a doubleword for an operand-size attribute of 32 bits. The first operand (a register) must be greater than or equal to the first bound in memory (lower bound), and less than or equal to the second bound in memory (upper bound). If the register is not within bounds, an Interrupt 5 occurs; the return EIP points to the BOUND instruction.
;The bounds limit data structure is usually placed just before the array itself, making the limits addressable via a constant offset from the beginning of the array.
; from https://courses.engr.illinois.edu/ece390/books/artofasm/CH06/CH06-5.html#HEADING5-171
;The fourth software interrupt, provided by 80286 and later processors, is the bound instruction. This instruction takes the form bound reg, mem
;and executes the following algorithm: if (reg [mem+sizeof(reg)]) then int 5
;[mem] denotes the contents of the memory location mem and sizeof(reg) is two or four depending on whether the register is 16 or 32 bits wide. The memory operand must be twice the size of the register operand. The bound instruction compares the values using a signed integer comparison.
; Intel’s designers added the bound instruction to allow a quick check of the range of a value in a register. This is useful in Pascal, for example, which checking array bounds validity and when checking to see if a subrange integer is within an allowable range. There are two problems with this instruction, however. On 80486 and Pentium/586 processors, the bound instruction is generally slower than the sequence of instructions it would replace: cmp reg, LowerBound
; jl OutOfBounds
; cmp reg, UpperBound
; jg OutOfBounds
;On the 80486 and Pentium/586 chips, the sequence above only requires four clock cycles assuming you can use the immediate addressing mode and the branches are not taken; the bound instruction requires 7-8 clock cycles under similar circumstances and also assuming the memory operands are in the cache.
; A second problem with the bound instruction is that it executes an int 5 if the specified register is out of range. IBM, in their infinite wisdom, decided to use the int 5 interrupt handler routine to print the screen. Therefore, if you execute a bound instruction and the value is out of range, the system will, by default, print a copy of the screen to the printer. If you replace the default int 5 handler with one of your own, pressing the PrtSc key will transfer control to your bound instruction handler. Although there are ways around this problem, most people don’t bother since the bound instruction is so slow.
; from http://faydoc.tripod.com/cpu/bound.htm
; Description
; Determines if the first operand (array index) is within the bounds of an array specified the second operand (bounds operand). The array index is a signed integer located in a register. The bounds operand is a memory location that contains a pair of signed doubleword-integers (when the operand-size attribute is 32) or a pair of signed word-integers (when the operand-size attribute is 16). The first doubleword (or word) is the lower bound of the array and the second doubleword (or word) is the upper bound of the array. The array index must be greater than or equal to the lower bound and less than or equal to the upper bound plus the operand size in bytes. If the index is not within bounds, a BOUND range exceeded exception (#BR) is signaled. (When a this exception is generated, the saved return instruction pointer points to the BOUND instruction.)
; The bounds limit data structure (two words or doublewords containing the lower and upper limits of the array) is usually placed just before the array itself, making the limits addressable via a constant offset from the beginning of the array. Because the address of the array already will be present in a register, this practice avoids extra bus cycles to obtain the effective address of the array bounds.
; from http://www.plantation-productions.com/Webster/www.artofasm.com/DOS/ch17/CH17-2.html#HEADING2-27
; Like into, the bound instruction will cause a conditional exception. If the specified register is outside the specified bounds, the bound instruction is equivalent to an int 5 instruction; if the register is within the specified bounds, the bound instruction is effectively a nop.
; The return address that bound pushes is the address of the bound instruction itself, not the instruction following bound. If you return from the exception without modifying the value in the register (or adjusting the bounds), you will generate an infinite loop because the code will reexecute the bound instruction and repeat this process over and over again.
; Warning: IBM, in their infinite wisdom, decided to use int 5 as the print screen operation. The default int 5 handler will dump the current contents of the screen to the printer. This has two implications for those who would like to use the bound instruction in their programs. First, if you do not install your own int 5 handler and you execute a bound instruction that generates a bound exception, you will cause the machine to print the contents of the screen. Second, if you press the PrtSc key with your int 5 handler installed, BIOS will invoke your handler. The former case is a programming error, but this latter case means you have to make your bounds exception handler a little smarter. It should look at the byte pointed at by the return address. If this is an int 5 instruction opcode (0cdh), then you need to call the original int 5 handler, or simply return from interrupt (do you want them pressing the PrtSc key at that point?). If it is not an int 5 opcode, then this exception was probably raised by the bound instruction. Note that when executing a bound instruction the return address may not be pointing directly at a bound opcode (0c2h). It may be pointing at a prefix byte to the bound instruction (e.g., segment, addressing mode, or size override). Therefore, it is best to check for the int 5 opcode.
; test the “bound” instruction:
; mov ax, 3
; mov [stackupperbound], ax
; mov ax, 1
; mov [stacklowerbound], ax
; mov ax, 0
; ;bound ax, [stacklowerbound]
; bound ax, stacklowerbound
; push ‘ ‘
%endif ; TESTBOUNDMANUALLY
loop stackoverloadloop
finishtestinterrupt5:
xor cx, cx
mov cx, [numberofpushrequired]
; 4/3/2014 not unpush-ing caused error until To^nAn remembers how the water fountain was topped with boyscout fleur-de-lis flower symbol at third nursery we visited in California before co^ Be^ uncle David Lowe came and before we return home to Michinga: “leave campground as you found it”
unpushloop:
pop ax
loop unpushloop
nop
; test int 9 here ………………..
; automatic interrupt: keyboard presses will create int 9 …
; test: however ctr-alt-del will have no effect on custom interrupt int 9 …
;;mov ax, [interrupt9count]
;;mov [previousinterrupt9count], ax
;xor cx, cx
waitforinterrupts:
; cmp [previousinterrupt9count], [interrupt9count]
;SAFEPUSH ‘ ‘
;;cmp SP, stacksegment + 10
;;ja safetopush
;;notsafetopush: int 5
;;safetopush: push ‘ ‘
cmp byte [interrupt9count], 10 ; key press wait loop … each press-release generates 2 interrupts …
jne waitforinterrupts
;loopne waitforinterrupts
; xor cx, cx
;WaitforData: in al, 64h ;Read kbd status port.
; test al, 10b ;Data in buffer?
; loopz WaitforData ;Wait until data available.
; restore original interrupt vector table from BIOS with original interrupt numbers 5 and 9 service routines
; call changeivt.loadivtwithorgbiosivt
call changeivt.loadbiosivtwithorgbiosivt
call changeivt.setorgivt
; ctr-alt-del should have an effect again here ………….
jmp seeyoulater
%endif ; TRYIVT
%ifdef TRYIVTORIG
; cli ; disable interrupts during change of interrupt vector table
;; call changeivt.loadorgbiosivtwithbiosivt
;call changeivt.loadivtwithbiosivt
;; call changeivt.loadivtwithorgbiosivt
;Setting:
;mov ax, [intnum*4] ; offset
;mov ax [intnum*4+2] ; segment
; pbs “peg and cat” …. suggestively similar “peg and cat” bedding at baby r us 3/13/2014
; substitute custom interrupt numbers 5 and 9 into new ivt table created by cloning from original BIOS ivt table: neighbor dude with custom truck 3/13/2014
; address of BIOS interrupts routines
interrupt5segment dw 0
interrupt5offset dw 0
interrupt9segment dw 0
interrupt9offset dw 0
mov ax, 0x0
mov gs, ax
mov ax, [gs:5*4] ; [0x0:5*4]
mov [interrupt5offset], ax
mov ax, [gs:5*4+2] ; [0x0:5*4+2]
mov [interrupt5segment], ax
mov ax, [gs:9*4] ; [0x0:9*4]
mov [interrupt5offset], ax
mov ax, [gs:9*4+2] ; [0x0:9*4+2]
mov [interrupt5segment], ax
; mov dword [interrupt5serviceroutine], [0x0:5*4]
; mov dword [interrupt9serviceroutine], [0x0:9*4]
cli ; pause interrupts
mov AX, safeinterrupt5sr ; offset
; mov dword [ivt + 5*4], AX
mov [gs:5*4], AX
mov AX, PROGRAMSEGMENT ; segment
; mov dword [ivt + 5*4+2], AX
mov [gs:5*4+2], AX
mov AX, safeinterrupt9sr ; offset
; mov dword [ivt + 9*4], AX
mov [gs:9*4], AX
mov AX, PROGRAMSEGMENT ; segment
; mov dword [ivt + 9*4+2], AX
mov [gs:9*4+2], AX
sti ; re-enable interrupts
;call changeivt.loadbiosivtwithivt
;; call changeivt.setivt ; inform processor where new ivt table is …
;sti ; re-enable interrupts
; test custom interrupt numbers 5 and 9 … here …
int 5
int 9
; restore original interrupt vector table from BIOS with original interrupt numbers 5 and 9
; call changeivt.loadivtwithorgbiosivt
;; call changeivt.loadbiosivtwithorgbiosivt
;; call changeivt.setorgivt
cli ; pause interrupts
mov ax, [interrupt5offset]
mov [gs:5*4], ax
mov ax, [interrupt5segment]
mov [gs:5*4+2], ax
mov ax, [interrupt9offset]
mov [gs:9*4], ax
mov ax, [interrupt9segment]
mov [gs:9*4+2], ax
sti ; re-enable interrupts
;sti ; re-enable interrupts
%endif ; TRYIVTORIG
;%define TRYIVT 1 ; non-zero
%ifdef TRYIVT
; from Programmer’s Reference Manual
;IF PE = 0
;THEN GOTO REAL-ADDRESS-MODE;
;ELSE GOTO PROTECTED-MODE;
;FI;
;REAL-ADDRESS-MODE:
; Push (FLAGS);
; IF = 0; (* Clear interrupt flag *)
; TF = 0; (* Clear trap flag *)
; Push(CS);
; Push(IP);
; (* No error codes are pushed *)
; CS := IDT[Interrupt number * 4].selector;
; IP := IDT[Interrupt number * 4].offset;
;interrupts are a type of (messageA + messageB + messageC + messageD + tinLa`nh + …):
; from http://wiki.osdev.org/Interrupt_Vector_Table
; The IVT is typically located at 0000:0000H, and is 400H bytes in size (4 bytes for each interrupt). Although the default address can be changed using the LIDT instruction on newer CPUs, this is usually not done because it is both inconvenient and incompatible with other implementations and/or older software (e.g. MS-DOS programs). However, note that the code must remain in the first MiB of RAM.
; format of the ivt table entries [1024/4=256 entries] is
; +———–+———–+
; | Segment | Offset |
; +———–+———–+
; 4 2 0
; from https://www.uop.edu.jo/issa/Assembly/programming.pdf
;ivt table is 1k in real mode, 2k in protected mode
;ivt entry is 4 bytes in real mode, 8 bytes in protected mode
;size of the pointer to ivt table is 4 bytes for addresses from 00000000 to 000003FF, is 8 bytes in protected mode
;%define BIVTSTART 0x0; Start of BIOS ivt data area
;struc tBIOSIVT ; its structure
; .SEGMENT RESW 1
; .OFFSET RESW 1
;endstruc
; the ivt table defined in the data segment “datasegment” above
;;.ivt: times 1024 db 0 ; interrupt vector table: reserve space to push-pop BIOS’ ivt table
;;.ivtend:
;;fourcxvar dw 0
;; mov ax, 0x0
;; mov gs, ax
;; mov ax, [gs:5*4] ; [0x0:5*4]
;; mov [interrupt5offset], ax
;; mov ax, [gs:5*4+2] ; [0x0:5*4+2]
;; mov [interrupt5segment], ax
; from NASM manual:
;3.3 Effective Addresses
;An effective address is any operand to an instruction which references memory. Effective addresses, in NASM, have a very simple syntax: they consist of an expression evaluating to the desired address, enclosed in square brackets. For example:
;wordvar dw 123
; mov ax,[wordvar]
; mov ax,[wordvar+1]
; mov ax,[es:wordvar+bx] ; this is gives no error
; however:
; mov ax,[es:wordvar+cx] ; this gives “invalid effective address” error
; mov ax,[es:wordvar+2*bx] ; this gives “invalid effective address” error
; mov ax,[es:wordvar+10*bx] ; this gives “invalid effective address” error
; mov ax,[es:wordvar+4*bx] ; this gives “invalid effective address” error
; mov eax,[es:wordvar+4*ebx] ; this gives no error
; mov eax,[es:wordvar+10*ebx] ; this gives “invalid effective address” error
; also segment registers:
; mov gs, 0x0 ; “immediate” gives error
; mov gs, [worvar] ; “memory” is all right
; mov gs, ax ; “register” is all right
; from http://www.supernovah.com/Tutorials/Assembly3.php:
;16-bit Real Mode Addressing
;Non Memory Addressing Modes
;The non memory addressing modes in 16 bits are the same as 32-bit non memory addressing modes except that you can only use 16-bit registers or smaller. Also the largest displacement in 16-bit addresses can be at most 16 bits.
;Memory Addressing Modes
;In 16-bit real mode we can address memory using 16-bit or 8-bit registers. The addressing modes in 16 bits are much more restrictive than in 32 bits. The table below lists the components that can make up a 16-bit address.
;Displacement Base Index Scale
;no disp BX SI None
;8-bit disp BP DI
;16-bit disp
;32-bit Protected Mode Addressing
;Non Memory Addressing Modes
;These addressing modes do not access memory. These modes will work with either static data or registers.
;Memory Addressing Modes
;These addressing modes perform memory operations such as reading from and writing to memory. Because of the memory access, it is often slower than using the non memory addressing modes. Of course a program could not rely on immediate and register addressing modes alone, therefore the processor allows you to access memory in many different ways. Most instructions will only allow one operand to use a memory addressing mode while the other operand must use either the immediate or register addressing mode.
;Memory addresses are composed of several different components. The table below lists the components that can make up a memory address.
;Displacement Base Index Scale
;no disp EAX EAX 1
;16-bit disp EBX EBX 2
;32-bit disp ECX ECX 4
; EDX EDX 8
; ESI ESI
; EDI EDI
; EBP EBP
; ESP
; from Programmer’s Reference Manual:
;Figure 2-10. Effective Address Computation
; SEGMENT + BASE + (INDEX * SCALE) + DISPLACEMENT
;
; + +
; | — | + + + +
; + + | EAX | | EAX | | 1 |
; | CS | | ECX | | ECX | | | + +
; | SS | | EDX | | EDX | | 2 | | NO DISPLACEMENT |
; -| DS |- + -| EBX |- + -| EBX |- * -| |- + -| 8-BIT DISPLACEMENT |-
; | ES | | ESP | | — | | 4 | | 32-BIT DISPLACEMENT |
; | FS | | EBP | | EBP | | | + +
; | GS | | ESI | | ESI | | 6 |
; + + | EDI | | EDI | + +
; + + + +
changeivt:
.loadorgbiosivtwithbiosivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; setup loop counter
mov cx, 512 ; //1024 = 512 * sizeof(word) … setup loop counter
; loop instruction involves cx but 16 bit effective address requires bx …
.looploadorgbiosivtwithbiosivt:
mov word ax, [gs:bx] ; 16 bit effective address requires loop counter to use bx or bp instead of cx etc.
mov word [orgbiosivt + bx], ax
;mov dword [orgbiosivt + cx*4], [es:4*di]
sub bx, 2
loop .looploadorgbiosivtwithbiosivt
mov ax, [gs:0000]
mov [orgbiosivt + 0], ax ; since “loop” exists when CX is 0, 0th entry must be done manually
jmp .exitchangeivt
.loadbiosivtwithorgbiosivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; setup loop counter
mov cx, 512 ; //1024 = 512 * sizeof(word) … setup loop counter
.looploadbiosivtwithorigbiosivt:
mov word ax, [orgbiosivt + bx]
mov word [gs:bx], ax
sub bx, 2
loop .looploadbiosivtwithorigbiosivt
mov word ax, [orgbiosivt + 0] ; since “loop” exists when CX is 0, 0th entry must be done manually
mov word [gs:0], ax
jmp .exitchangeivt
.loadivtwithorgbiosivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; //1024 = 512 * sizeof(word) … setup loop counter
mov cx, 512 ; setup loop counter
.looploadivtwithorgbiosivt:
mov word ax, [orgbiosivt + bx]
mov word [ivt + bx], ax
sub bx, 2
loop .looploadivtwithorgbiosivt
mov word ax, [orgbiosivt + 0] ; since “loop” exists when CX is 0, 0th entry must be done manually
mov word [ivt + 0], ax
jmp .exitchangeivt
.loadivtwithbiosivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; //1024 = 512 * sizeof(word) … setup loop counter
mov cx, 512 ; setup loop counter
.looploadivtwithbiosivt:
mov word ax, [gs:bx] ; 16 bit effective address requires loop counter to use bx or bp instead of cx etc.
mov word [ivt + bx], ax
sub bx, 2
loop .looploadivtwithbiosivt
mov word ax, [gs:0] ; since “loop” exists when CX is 0, 0th entry must be done manually
mov word [ivt + 0], ax
jmp .exitchangeivt
.loadbiosivtwithivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; //1024 = 512 * sizeof(word) … setup loop counter
mov cx, 512 ; setup loop counter
.looploadbiosivtwithivt:
mov word ax, [ivt + bx]
mov word [gs:bx], ax
sub bx, 2
loop .looploadbiosivtwithivt
mov word ax, [ivt + 0] ; since “loop” exists when CX is 0, 0th entry must be done manually
mov word [gs:0], ax
jmp .exitchangeivt
.exitchangeivt:
ret
; from http://wiki.osdev.org/GDT_Tutorial
;gdtr DW 0 ; For limit storage
; DD 0 ; For base storage
;GDT:
;GDT_end:
;setGdt:
; xor EAX, EAX ; zero EAX register for use as scratch
; mov AX, DS ; the data segment “datasegment”
; shl EAX, 4 ; The linear address should here be computed as segment * 16 + offset. shift left 4 ~ multiply by 16
; add EAX, ”GDT” ; add offset to GDT structure in segment “datasegment”
; mov [gdtr + 2], eax ; initialize gdtr’s base storage to segment:offset address of GDT structure
; mov EAX, ”GDT_end”
; sub EAX, ”GDT” ; size of GDT structure = GDT end – GDT begin
; mov [gdtr], AX ; initialize gdtr’s to size of GDT structure = GDT end – GDT begin
; lgdt [gdtr] ; set the gdt with lgdt
; ret
; the idt or ivt table defined in the data segment “datasegment” above
;;.ivt: times 1024 db 0 ; interrupt vector table: reserve space to push-pop BIOS’ ivt table
;;.ivtend:
;;ivtend:
;; interrup descriptor table
;idt:
;idt_end:
;the idtr or ivtr structures defined in the data segment “datasegment” above:
;idtr DW 0 ; For limit storage
; DD 0 ; For base storage
;ivtr DW 0 ; For limit storage
; DD 0 ; For base storage
;.setidt: ; set the interrupt descriptor table IDT
.setivt: ; set the interrupt vector table IVT
xor EAX, EAX ; zero EAX register for use as scratch
mov AX, DS ; the data segment “datasegment”
shl EAX, 4 ; The linear address should here be computed as segment * 16 + offset. shift left 4 ~ multiply by 16
; add EAX, idt ; add offset to IDT structure in segment “datasegment”
add EAX, ivt ; add offset to IVT structure in segment “datasegment”
; mov [idtr + 2], eax ; initialize gdtr’s base storage to segment:offset address of IDT structure
mov [ivtr + 2], eax ; initialize ivtr’s base storage to segment:offset address of IVT structure
; mov EAX, idt_end
mov EAX, ivtend
; sub EAX, idt ; size of GDT structure = IDT end – IDT begin
sub EAX, ivt ; size of IDT structure = IVT end – IVT begin
; mov [idtr], AX ; initialize gdtr’s to size of IDT structure = IDT end – IDT begin
mov [ivtr], AX ; initialize ivtr’s to size of IVT structure = IVT end – IVT begin
; lgdt [idtr] ; set the idt with lgdt
;lgdt [ivtr] ; set the ivt with lgdt
lidt [ivtr] ; set the ivt with lgdt
; from Programmer’s Reference Manual
; IF instruction = LIDT
;THEN
; IF OperandSize = 16
; THEN IDTR.Limit:Base := m16:24 (* 24 bits of base loaded *)
; ELSE IDTR.Limit:Base := m16:32
; FI;
;ELSE (* instruction = LGDT *)
; IF OperandSize = 16
; THEN GDTR.Limit:Base := m16:24 (* 24 bits of base loaded *)
; ELSE GDTR.Limit:Base := m16:32;
; FI;
;FI;
;.exit:
;ret
jmp .exitchangeivt
.setorgivt: ; set the interrupt vector table IVT
xor EAX, EAX ; zero EAX register for use as scratch
; mov AX, DS ; the data segment “datasegment”
mov AX, 0x0 ; the data segment “datasegment”
shl EAX, 4 ; The linear address should here be computed as segment * 16 + offset. shift left 4 ~ multiply by 16
; add EAX, idt ; add offset to IDT structure in segment “datasegment”
; add EAX, ivt ; add offset to IVT structure in segment “datasegment”
add EAX, 0x0 ; add offset to IVT structure in segment “datasegment”
; mov [idtr + 2], eax ; initialize gdtr’s base storage to segment:offset address of IDT structure
mov [orgbiosivtr + 2], eax ; initialize ivtr’s base storage to segment:offset address of IVT structure
; mov EAX, idt_end
mov EAX, orgbiosivtend
; sub EAX, idt ; size of GDT structure = IDT end – IDT begin
sub EAX, orgbiosivt ; size of IVT structure = IVT end – IVT begin
; mov [idtr], AX ; initialize gdtr’s to size of IDT structure = IDT end – IDT begin
; mov [ivtr], AX ; initialize ivtr’s to size of IVT structure = IVT end – IVT begin
mov AX, 400h ; initialize size of ivtr to … size of original BIOS IVT structure
mov [orgbiosivtr], AX ; initialize original BIOS ivtr’s to size of original IVT structure = IVT end – IVT begin
; lgdt [idtr] ; set the idt with lgdt
;lgdt [orgbiosivtr] ; set the ivt with lgdt
lidt [orgbiosivtr] ; set the ivt with lgdt
; from Programmer’s Reference Manual
; IF instruction = LIDT
;THEN
; IF OperandSize = 16
; THEN IDTR.Limit:Base := m16:24 (* 24 bits of base loaded *)
; ELSE IDTR.Limit:Base := m16:32
; FI;
;ELSE (* instruction = LGDT *)
; IF OperandSize = 16
; THEN GDTR.Limit:Base := m16:24 (* 24 bits of base loaded *)
; ELSE GDTR.Limit:Base := m16:32;
; FI;
;FI;
;.exit:
;ret
jmp .exitchangeivt
; pbs “peg and cat” …. suggestively similar “peg and cat” bedding at baby r us 3/13/2014
; substitute custom interrupt numbers 5 and 9 into new ivt table created by cloning from original BIOS ivt table: neighbor dude with custom truck 3/13/2014
.insertcustominterruptsintoivt:
cli ; pause interrupts
mov AX, safeinterrupt5sr ; offset
; mov dword [ivt + 5*4], AX
;; mov [gs:5*4], AX ; insert offset part of address of custom interrupt service routine into BIOS ivt
mov [ivt + 5*4], AX ; insert offset part of address of custom interrupt service routine into ivt
mov AX, PROGRAMSEGMENT ; segment
; mov dword [ivt + 5*4+2], AX
;; mov [gs:5*4+2], AX ; insert segment part of address of custom interrup service routine into BIOS ivt
mov [ivt + 5*4+2], AX ; insert segment part of address of custom interrup service routine into ivt
mov AX, safeinterrupt9sr ; offset
; mov dword [ivt + 9*4], AX
;; mov [gs:9*4], AX ; insert offset part of address of custom interrupt service routine into BIOS ivt
mov [ivt + 9*4], AX ; insert offset part of address of custom interrupt service routine into ivt
mov AX, PROGRAMSEGMENT ; segment
; mov dword [ivt + 9*4+2], AX
;; mov [gs:9*4+2], AX ; insert segment part of address of custom interrupt service routine into BIOS ivt
mov [ivt + 9*4+2], AX ; insert segment part of address of custom interrupt service routine into ivt
sti ; re-enable interrupts
jmp .exitchangeivt
;;.removecustominterruptsfromivt
; restore original interrupt vector table from BIOS with original interrupt numbers 5 and 9
; call changeivt.loadivtwithorgbiosivt
;; call changeivt.loadbiosivtwithorgbiosivt
;; call changeivt.setorgivt
;; cli ; pause interrupts
;; mov ax, [interrupt5offset]
;; mov [gs:5*4], ax
;; mov ax, [interrupt5segment]
;; mov [gs:5*4+2], ax
;; mov ax, [interrupt9offset]
;; mov [gs:9*4], ax
;; mov ax, [interrupt9segment]
;; mov [gs:9*4+2], ax
;; sti ; re-enable interrupts
;sti ; re-enable interrupts
;; jmp .exitchangeivt
%endif ; TRYIVT
; gia ba?o suggested for balance to “say hello”:
seeyoulater:
; call exit
call word exit
; call hang
call word hang
ret ; return
; from http://www.supernovah.com/Tutorials/BootSector4.php:
;Video Memory
;As previously stated, what is printed to the screen is simply controlled by a special section of memory called
;the video memory (or VGA memory). This section of memory is then periodically copied to the video device
;memory which is then presented to the screen by the Digital Analog Converter (DAC). Currently we are in text
;mode 03h which is a form of EGA. The video memory for text mode 3h begins at 0xB8000. Text mode 03h is 80 characters wide
;and 25 characters tall. This gives us 2000 total characters (80 * 25). Each character consists of 2 bytes which
;yields 4000 bytes of memory in total. So this means that text mode 03h stores it’s video information (the information that is
;printed to the screen) at the memory address 0xB8000 and it takes up 4000 bytes of memory.
;Printing Character to the Screen
;The first we must do in order to print character to the screen is to get a segment register setup that points
;to the memory location 0xB8000 [= 753664 = 47104 * 16]. Remember that segments in real mode have the lower four bits implicitly
;set to zero and because each hex digit represents four bits we can easily drop the right most zero on the
;memory address when storing it in a segment register. We will use the ES segment register because we
;still want to access our data with the DS segment so we don’t run into problems when using instructions that
;implicitly use the DS segment by default.
;mov AX,0xB800 ;// = 47104
;mov ES,AX
;screen output …
;for the screen, the messages in (“muo^n loa`i” <= "muo^n loa`i va` messageA va` messageB va` messageC va` ….") are pixels …
;("muo^n loa`i va` pixel1 va` pixel2 va` … ddu+o+.c so^'ng la^u bi`nh thu+o+`ng; everyone live long and well")
screensetup: ; point ES to video memory
.setupvideosegment:
mov AX,0xB800 ;// = 47104
mov ES,AX
; to use the stack, use "call" and "ret" instead of "jmp"
; or just let the program flows, without the jmp, to instructions that follow
;jmp clearscreenpixels
ret ; return
; from http://staff.ustc.edu.cn/~xyfeng/research/cos/resources/machine/mem.htm:
;0x0000:0x0000 1024 bytes Interrupt Vector Table
;0x0040:0x0000 256 bytes BIOS Data Area
;0x0050:0x0000 ? Free memory
;0x07C0:0x0000 512 bytes Boot sector code
;0x07E0:0x0000 ? Free memory
;0xA000:0x0000 64 Kb Graphics Video Memory
;0xB000:0x0000 32 Kb Monochrome Text Video Memory
;0xB800:0x0000 32 Kb Color Text Video Memory
;0xC000:0x0000 256 Kb1 ROM Code Memory
;0xFFFF:0x0000 16 bytes More BIOS data
;Clearing the Background
;Clearing the background is rather trivial. The goal is to set all of the attribute bytes to the background color
;you wish to clear it to. The basic idea is to create a loop that will set every other byte, starting at the first
;attribute byte, to the background color we wish to clear to. We must also be sure to only clear all of the attributes that
;are used to represent the string. In other words, be sure not to go past the last attribute byte. The last attribute byte is
;found at 80 * 25 * 2 – 1. The 80 is the width and the 25 is the height. The 2 is there because two bytes make up each
;character; one for the character and one for the attribute. Finally the 1 is subtracted because our first attribute byte is
;actually the second byte at the beginning The 1 simply takes into account that we start our count at one instead of zero.
;The right most hex digit sets the lower four bits of the attribute byte. The lower four bits control the character color while the upper
;four bits (the left most hex digit) control the background color and flash bit. We set the background and flash bits (upper four bits) to 0h
; because 0h corresponds to the color black with no flashing.
;color index hex 64-color palette index
;Black 0 00h 0
;Blue 1 01h 1
;Green 2 02h 2
;Cyan 3 03h 3
;Red 4 04h 4
;Magenta 5 05h 5
;Brown 6 06h 20
;Light Gray 7 07h 7
;Dark Gray 8 08h 56
;Bright Blue 9 09h 57
;Bright Green 10 0Ah 58
;Bright Cyan 11 0Bh 59
;Bright Red 12 0Ch 60
;Bright Magenta 13 0Dh 61
;Bright Yellow 14 0Eh 62
;Bright White 15 0Fh 63
; from http://gd.tuwien.ac.at/languages/c/programming-bbrown/advcw2.htm and
;offset = (( row * 0x50 + column ) * 2 ) + ( pagenum * 0x1000 )
clearscreenpixels:
mov CX,0x50 * 25 * 2 – 1
mov BX,1
.Loopthroughscreenpixels:
cmp BX,CX
ja .finishclearscreenpixels ;CF = 0 and ZF = 0
;ja Loads EIP with the specified address, if first operand of previous CMP instruction is greater than the second. ja is the same as jg, except that it performs an unsigned comparison.
mov byte [ES:BX],70h ;Set background to light gray
;and the text to black
;with no flashing text
add BX,2
jmp .Loopthroughscreenpixels ; jmp Loads EIP with the specified address
.finishclearscreenpixels:
; to use the stack, use "call" and "ret" instead of "jmp"
; or just let the program flows, without the jmp, to instructions that follow
;jmp exit
;jmp sayhello
ret
%ifdef SAYHELLO
sayhello:
mov byte [ES:0],'h'
mov byte [ES:2],'o'
mov byte [ES:4],'p'
mov byte [ES:6],'e'
mov byte [ES:8],' '
mov byte [ES:10],'w'
mov byte [ES:12],'e'
mov byte [ES:14],'l'
mov byte [ES:16],'l'
; from NASM manual
; wordvar dw 123
; mov ax,[wordvar]
; mov ax,[wordvar+1]
; mov ax,[es:wordvar+bx]
; test stacksegment ; stack ~ buffer … to^nan does not have enough fat/buffer on him
; xor bl, bl
; from http://www.supernovah.com/Tutorials/Assembly4.php:
;When the processor pushes data onto the stack it does the following operations:
;1.Subtract 4 from SP or ESP
;2.Move the source data to the memory location [SS:SP] or [SS:ESP]
; push dword 117 ;Push the value 117 as a dword onto the stack
; push dword [0x500] ;Push the value at the memory location 0x500 onto the stack
; push byte 'H' ;Push the value 117 as a dword onto the stack ; nasm gives no error with the "byte" specification, see http://f.osdev.org/viewtopic.php?f=1&t=13399
; push byte 'o' ;Push the value 117 as a dword onto the stack
; push byte 'p' ;Push the value 117 as a dword onto the stack
; push byte 'e' ;Push the value 117 as a dword onto the stack
; push byte 'W' ;Push the value 117 as a dword onto the stack
; push byte 'e' ;Push the value 117 as a dword onto the stack
; push byte 'l' ;Push the value 117 as a dword onto the stack
; from http://www.supernovah.com/Tutorials/BootSector4.php:
; When the processor pushes data onto the stack it does the following operations:
;1.Subtract 4 from SP or ESP
;2.Move the source data to the memory location [SS:SP] or [SS:ESP]
; from Programmer's Reference Manual
;IF StackAddrSize = 16
;THEN
; IF OperandSize = 16 THEN
; SP := SP – 2;
; (SS:SP) := (SOURCE); (* word assignment *)
; ELSE
; SP := SP – 4;
; (SS:SP) := (SOURCE); (* dword assignment *)
; FI;
;ELSE (* StackAddrSize = 32 *)
; IF OperandSize = 16
; THEN
; ESP := ESP – 2;
; (SS:ESP) := (SOURCE); (* word assignment *)
; ELSE
; ESP := ESP – 4;
; (SS:ESP) := (SOURCE); (* dword assignment *)
; FI;
;FI;
; thus, …
; push word ….. subtracts 2 from SP or ESP
; push dword ….. subtracts 4 from SP or ESP
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; mov [spprevious], SP
; from NASM manual
;A character constant with more than one byte will be arranged with little-endian order in mind: if you code
; mov eax,'abcd'
;then the constant generated is not 0x61626364, but 0x64636261, so that if you were then to store the value into memory, it would read abcd rather than dcba. This is also the sense of character constants understood by the Pentium's CPUID instruction.
; … db 0x55 ; just the byte 0x55
; NOTE:
;mov stacktop, SP ; invalid combination of opcode and operands
;mov BP, SP ; valid
;stackdata dw 0 ; valid
;mov ax, [bp] ; valid
;mov [stackdata], ax ; valid
;stackpointer dw 0
;mov [stackpointer], SP ; valid
; mov [stackdata], [[stackpointer]] ; effectively data on stack is accessed thus …
mov BP, SP
;;mov [stackpointer], SP ; SP ~ (stacktop – amount that have been pushed)
; push 'H ' ;Push the value 117 as a dword onto the stack
push word 'H ' ;Push the value 117 as a dword onto the stack
;pushd 'H ' ;Push the value 117 as a dword onto the stack
;pushw 'H ' ;Push the value 117 as a dword onto the stack
;push word 'H ' ;Push the value 117 as a dword onto the stack
;push dword 'H ' ;Push the value 117 as a dword onto the stack
; mov [spnew], SP
; mov word [spcounter + 2 * 2], spprevious – spnew
; mov bx, sp ; sp ~ stacktop – amount that have been pushed
; 3/27/2014: co^ Tu' chu' Ha?i came today and To^nAn figures out to use BL register together with BP and SP register to get at the data on the stack by dereferencing register SP …
mov BL, [BP – 2]
;;mov byte al, [stackpointer – 2]
mov byte [ES:260], BL ; 'H '
;; mov [stackpointer], SP ; SP ~ (stacktop – amount that have been pushed)
;; push 'O ' ;Push the value 117 as a dword onto the stack
push word 'O ' ;Push the value 117 as a dword onto the stack
;; mov byte bl, [stackpointer – 2 + 1]
;; mov byte [ES:262], bl ; 'O '
;; mov [stackpointer], SP ; SP ~ (stacktop – amount that have been pushed)
;; push 'P ' ;Push the value 117 as a dword onto the stack
push word 'P ' ;Push the value 117 as a dword onto the stack
;; mov byte bl, [stackpointer – 2 + 1]
;; mov byte [ES:264], bl ; 'O '
;; mov [stackpointer], SP ; SP ~ (stacktop – amount that have been pushed)
;; push 'E ' ;Push the value 117 as a dword onto the stack
push word 'E ' ;Push the value 117 as a dword onto the stack
;; mov byte bl, [stackpointer – 2 + 1]
;; mov byte [ES:266], bl ; 'E '
;; mov [stackpointer], SP ; SP ~ (stacktop – amount that have been pushed)
;; push 'W ' ;Push the value 117 as a dword onto the stack
push word 'W ' ;Push the value 117 as a dword onto the stack
;; mov byte bl, [stackpointer – 2 + 1]
;; mov byte [ES:270], bl ; 'W '
;; mov [stackpointer], SP ; SP ~ (stacktop – amount that have been pushed)
;; push 'E ' ;Push the value 117 as a dword onto the stack
push word 'E ' ;Push the value 117 as a dword onto the stack
;; mov byte bl, [stackpointer – 2 + 1]
;; mov byte [ES:272], bl ; 'E '
;; mov [stackpointer], SP ; SP ~ (stacktop – amount that have been pushed)
;; push 'L ' ;Push the value 117 as a dword onto the stack
push word 'L ' ;Push the value 117 as a dword onto the stack
;; mov byte bl, [stackpointer – 2 + 1]
;; mov byte [ES:274], bl ; 'L '
;stacktop = stacksegment – datasegment + 64
; xor bl, bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 0] ; 'l'
; mov byte [ES:30], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 1] ; 'e'
; mov byte [ES:32], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 2] ; 'W'
; mov byte [ES:34], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 3] ; 'e'
; mov byte [ES:36], bl
xor bl, bl
; STACK states at various points …
; *****************
; *****************
; *****************
; *****************
; ***************** << SP
; ***************** 2 bytes after call main
; *****************
; *****************
; *****************
; ***************** << SP
; ***************** + 2 bytes after call sayhello
; *****************
; ***************** 2 bytes after call main
; *****************
; ***************** <Convert Character to Number!
; mov i,al
;
; MOV AH, 2 ;
; MOV DL, i ; Print Character.
; INT 21H ;
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; xor bl, bl
; mov byte bl, [spcounter + 2 * 0]
; mov byte [ES:76], bl
; mov byte bl, [spcounter + 2 * 1]
; mov byte [ES:7], bl
; mov byte bl, [spcounter + 2 * 2]
; mov byte [ES:], bl
xor bl, bl
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘L ‘
;mov byte bl, [stacktop – 0]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
mov byte [ES:56], bl
;mov byte bl, [stacktop – 4]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘E ‘
mov byte [ES:54], bl
;mov byte bl, [stacktop – 8]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘W ‘
mov byte [ES:52], bl
;mov byte bl, [stacktop – 12]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘E ‘
mov byte [ES:46], bl
;mov byte bl, [stacktop – 16]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘P ‘
mov byte [ES:44], bl
;mov byte bl, [stacktop – 20]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘O ‘
mov byte [ES:42], bl
;mov byte bl, [stacktop – 24]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘H ‘
mov byte [ES:40], bl
; test datasegment
xor bl, bl
mov byte bl, [datasegment]
; mov byte bl, [0]
; mov byte bl, [DS:0]
mov byte [ES:20], bl
mov byte bl, [datasegment + 1]
; mov byte bl, [1]
mov byte [ES:22], bl
mov byte bl, [datasegment + 2]
; mov byte bl, [2]
mov byte [ES:24], bl
mov byte bl, [datasegment + 3]
; mov byte bl, [3]
mov byte [ES:26], bl
mov byte bl, [datasegment + 4]
; mov byte bl, [4]
mov byte [ES:28], bl
mov byte bl, [datasegment + 5]
; mov byte bl, [5]
mov byte [ES:30], bl
mov byte bl, [datasegment + 6]
; mov byte bl, [6]
mov byte [ES:32], bl
mov byte bl, [datasegment + 7]
; mov byte bl, [7]
mov byte [ES:34], bl
; mov byte [ES:16], [datasegment + 1]
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
;jmp exit
ret ; sayhello
;%macro OUTPUTHEXNUMBER 0
; following code for input/output numbers is from http://www.ece.msstate.edu/~janem/ECE3724/S03/Presentations/number_io.ppt
;Output an 8 bit number in Hex Format
;•Two Hex characters in 8-bits. Want to work with each set of 4-bits individually.
;•Each Hex character represents 4-bits in a number.
;◦0000 = ‘0’ (ASCII code = 30h)
;◦0001 = ‘1’ (ASCII code = 31h)
;◦1001 = ‘9’ (ASCII code = 39h)
;◦……
;◦1010 = ‘A’ (ASCII code = 41h)
;◦1011 = ‘B’ (ASCII code = 42h)
;◦……
;◦1111 = ‘F’ (ASCII code) = 46h ).
;•If 4-bits is between 0-9, then ASCII = 30h + 4bits
;•If 4-bits is between A-F, then ASCII = 37h + 4bits
;%macro DISPLAYREGISTERCHARACTERS 2 ; expects AL, DI loaded with appropriate values …
displaycharacter: ; expects AL, DI loaded with appropriate values …
xor BL, BL
;mov byte BL, al ;
;; mov byte BL, %1 ; %1 = r/mm = register/memory containing character
mov byte BL, AL ; %1 = r/mm = register/memory containing character
;; mov byte [ES:300], BL ; ‘H ‘
mov byte [ES:DI], BL ; ‘H ‘ ; %2 = character screen position
ret ; displaycharacter
;%endmacro ; DISPLAYCHARACTER
;Displacement Base Index Scale
;no disp BX SI None
;8-bit disp BP DI
;16-bit disp
; from http://faydoc.tripod.com/cpu/jmp.htm :
;Description
; Transfers program control to a different point in the instruction stream without recording return information. The destination (target) operand specifies the address of the instruction being jumped to. This operand can be an immediate value, a general-purpose register, or a memory location.
;
;This instruction can be used to execute four different types of jumps:
; Near jump A jump to an instruction within the current code segment (the segment currently pointed to by the CS register), sometimes referred to as an intrasegment jump.
; Short jump A near jump where the jump range is limited to –128 to +127 from the current EIP value.
; Far jump A jump to an instruction located in a different segment than the current code segment but at the same privilege level, sometimes referred to as an intersegment jump.
; Task switch A jump to an instruction located in a different task.
;
;A task switch can only be executed in protected mode (see Chapter 6, Task Management, in the Intel Architecture Software Developer’s Manual, Volume 3, for information on performing task switches with the JMP instruction).
;%macro OUT1HEXMACRO 1
out1hex:
cmp AL, 0x09 ; is 4-bit value above 9 – i.e. a “number” 0-9
;jg skip ; jg “jump if greater” is signed, ja “jump if above” is unsigned
;•If 4-bits is between A-F, then ASCII = 37h + 4bits
ja isCharacter ; if “greater than”, then must be a character
; ISCHARACTERMACRO %1 ; if “greater than”, then must be a character
add AL, 0x30 ;•If 4-bits is between 0-9, then ASCII = 30h + 4bits
call displaycharacter
;DISPLAYREGISTERCHARACTERS AL, DI
jmp finishout1hex
;ret
;%endmacro ; OUT1HEXMACRO
;;out1hexhigh:
;; cmp AH, 0x09 ; is 4-bit value above 9 – i.e. a “number” 0-9
;; ;jg skip ; jg “jump if greater” is signed, ja “jump if above” is unsigned
;; ja isCharacter ; if “greater than”, then must be a character
;; add AH, 0x30
;; ;call displaycharacter
;; DISPLAYREGISTERCHARACTERS AH, DI
;; ret ; or use jmp finishout1hex below
;; jmp finishout1hex
;%macro ISCHARACTERMACRO 1
isCharacter:
add AL, 0x37 ;•If 4-bits is between A-F, then ASCII = 37h + 4bits
call displaycharacter
;DISPLAYREGISTERCHARACTERS AL, DI
jmp finishout1hex
finishout1hex:
ret
;%endmacro ; ISCHARACTERMACRO
;%macro OUT2HEXMACRO 1
out2hex: ; output value in ‘al’ as 2 hex character
;push byte AL ; save al
;push word AX ; save al
;push dword EAX ; save al
push AX ; save al
shr AL, 4 ; get most sig. 4 bits into lower
;;mov DI, 300 ; screen position to print out character
call out1hex ; print most sig. hex digit
; OUT1HEXMACRO %1 ; print most sig. hex digit
pop AX ; get back original al
and AL, 0x0F ; upper 4 bits = 0 – working with low 4 bits
;;mov DI, 302 ; screen position to print out character
add DI, 2 ; move screen position one over
call out1hex ; print least sig. hex digit
; OUT1HEXMACRO %1 + 1 ; print least sig. hex digit
ret
;%endmacro ; OUT2HEXMACRO
;out4hex:
; push AX ; save al
; shr AH, 4 ; get most sig. 4 bits into lower
; call out1hexhigh ; print most sig. hex digit
; pop AX ; get back original al
; and AH, 0x0F ; upper 4 bits = 0 – working with low 4 bits
; call out1hexhigh ; print least sig. hex digit
; push AX ; save al
; shr AL, 4 ; get most sig. 4 bits into lower
; call out1hex ; print most sig. hex digit
; pop AX ; get back original al
; and AL, 0x0F ; upper 4 bits = 0 – working with low 4 bits
; call out1hex ; print least sig. hex digit
; ret ; out4hex
;out32bithex:
; push EAX ; save EAX
; shr EAX, 16 ; get the most sig. 16 bits into lower
; call out4hex ;
; pop EAX ; restore EAX
; ;push EAX ; save EAX
; call out4hex
; ;pop EAX ; restore EAX
; ret ; out4hex
;%endmacro ; OUTPUTHEXNUMBER
; test interrupt-support stack boundaries
; from http://www.eecg.toronto.edu/~amza/www.mindsec.com/files/x86regs.html
;SS:EBP EBP BP : Stack Base pointer register
; Holds the base address of the [current] stack [frame]
;SS:ESP ESP SP : Stack pointer register
; Holds the top address of the stack
; from NASM manual:
;4.3 Multi-Line Macros: %macro
;Multi-line macros are much more like the type of macro seen in MASM and TASM: a multi-line macro definition in NASM looks something like this.
;%macro prologue 1
; push ebp
; mov ebp,esp
; sub esp,%1
;%endmacro
; from Programmer’s Reference Manual:
;1.The stack pointer (ESP) register. ESP points to the top of the push-down stack (TOS). It is referenced implicitly by PUSH and POP operations, subroutine calls and returns, and interrupt operations. When an item is pushed onto the stack (see Figure 2-7 ), the processor decrements ESP, then writes the item at the new TOS. When an item is popped off the stack, the processor copies it from TOS, then increments ESP. In other words, the stack grows down in memory toward lesser addresses.
; BOUND instruction:
;62 /r BOUND r16,m16&16 10 Check if r16 is within bounds
; (passes test)
;62 /r BOUND r32,m32&32 10 Check if r32 is within bounds
; (passes test)
;IF (LeftSRC [RightSRC + OperandSize/8])
; (* Under lower bound or over upper bound *)
;THEN Interrupt 5;
;FI;
; note: because “int #” instruction will use stack to store CS:IP and FLAGS,
; Push (FLAGS);
; Push(CS);
; Push(IP);
; have to allow on the stack for that much room 32 bits + 32 bits = 4 bytes + 4 bytes …
; from Programmer’s Reference Manual for INT instruction:
; REAL-ADDRESS-MODE:
; Push (FLAGS);
; IF = 0; (* Clear interrupt flag *)
; TF = 0; (* Clear trap flag *)
; Push(CS);
; Push(IP);
; (* No error codes are pushed *)
; CS := IDT[Interrupt number * 4].selector;
; IP := IDT[Interrupt number * 4].offset;
; from Programmer’s Reference Manual
; IRET (Return From Interrupt) returns control to an interrupted procedure. IRET differs from RET in that it also pops the flags from the stack into the flags register. The flags are stored on the stack by the interrupt mechanism.
%endif ; SAYHELLO
; SAFEWAY grocery …
;;%macro SAFECALL 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safecallinterrupt int 5
;; bound SP, stacklowerbound + 4 + 4 ;
;; call %1
;;%endmacro
;;%macro SAFEPUSH 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safepushinterrupt int 5
;; bound SP, stacklowerbound + 4 + 4 ;
;; push %1
;;%endmacro
;;%macro SAFEPOP 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safepopinterrupt int 5
;; bound SP, stacklowerbound + 4 + 4 ;
;; pop %1
;;%endmacro
;;%macro SAFERET 1
; cmp SP, stacksegment
; jl safecallinterrupt
; saferetinterrupt int 5
;; bound SP, stacklowerbound + 4 + 4 ;
;; ret %1
;;%endmacro
; from http://www.mactech.com/macintosh-c/classic-chap01-1.html
; Macintosh Protection mechanism for the stack: “… every sixtieth of a second an Operating System task checks whether the stack has moved into the heap. If it has, the task, known as the stack sniffer, generates a system error …”
; Intel implements push-pop-able stack data structures such as IDT, GDT etc. defining limits for protection purposes …
; from Programmer’s Reference Manual
;6.2 Overview of 80386 Protection Mechanisms
;Protection in the 80386 has five aspects: 1. Type checking
;2. Limit checking
;3. Restriction of addressable domain
;4. Restriction of procedure entry points
;5. Restriction of instruction set
;The protection hardware of the 80386 is an integral part of the memory management hardware. Protection applies both to segment translation and to page translation.
;Each reference to memory is checked by the hardware to verify that it satisfies the protection criteria. All these checks are made before the memory cycle is started; any violation prevents that cycle from starting and results in an exception. Since the checks are performed concurrently with address formation, there is no performance penalty.
;Invalid attempts to access memory result in an exception. Refer to Chapter 9 for an explanation of the exception mechanism . The present chapter defines the protection violations that lead to exceptions.
;The concept of “privilege” is central to several aspects of protection (numbers 3, 4, and 5 in the preceeding list). Applied to procedures, privilege is the degree to which the procedure can be trusted not to make a mistake that might affect other procedures or data. Applied to data, privilege is the degree of protection that a data structure should have from less trusted procedures.
;The concept of privilege applies both to segment protection and to page protection.
;%macro SAFEINT5 0
; my/your own custom interrupt 5 service routine
safeinterrupt5sr:
;mov byte [wasinterrupted], 1
add byte [interrupt5count], 1
%define WHATISBP
%ifdef WHATISBP
; from Programmer’s Reference Manual
; CMP (Compare) subtracts the source operand from the destination operand. It updates OF, SF, ZF, AF, PF, and CF but does not alter the source and destination operands. A subsequent Jcc or
cmp BP, 0
jne bpisnotzero
bpiszero:
mov byte [ES:360], ‘0’
jmp donecomparingbp
bpisnotzero:
cmp BP, 0
;jl bpislessthanzero ; ; using jl will branch to give ‘L’, implying bpislessthanzero
;mov byte [ES:362], ‘G’
jb bpislessthanzero ; ; using jb will give ‘A’, implying bp is greater than zero
mov byte [ES:362], ‘A’
jmp donecomparingbp
bpislessthanzero:
;mov byte [ES:364], ‘L’
mov byte [ES:364], ‘B’
jmp donecomparingbp
donecomparingbp:
hlt
%endif ; WHATISBP
; because “bound” instruction uses “signed” values [jl vs. jb in WHATISBP test above] absolute lower bound is not “0” …
; … something to do with “two-complements” and “sign extension” … http://en.wikipedia.org/wiki/Signed_number_representations …
; from Pavel Šimerda website pavlix.net in Prague, Czech Republic @ http://stackoverflow.com/questions/19464202/how-does-c-complier-handle-unsigned-and-signed-integer-why-the-assembly-code-fo
;It’s quite easy. Operations like addition and subtraction don’t need any adjustment for signed types in two’s complement arithmetic. Just perform a mind experiment and imagine an algorithm using just the following mathematical operations:
;•increment by one
;•decrement by one
;•compare with zero
;Addition is just taking items one by one from one heap and putting them to the other heap until the first one is empty. Subtraction is taking from both of them at once, until the subtracted one is empty. In modular arithmetics, you just just treat the smallest value as the largest value plus one and it works. Two’s complement is just a modular arithmetic where the smallest value is negative.
;If you want to see any difference, I recommend you to try operations that aren’t safe with respect to overflow. One example is comparison (a < b).
; from http://en.wikipedia.org/wiki/Signed_number_representations
; Two's complement is the easiest to implement in hardware, which may be the ultimate reason for its widespread popularity[citation needed]. Processors on the early mainframes often consisted of thousands of transistors – eliminating a significant number of transistors was a significant cost savings. Mainframes such as the IBM System/360, the GE-600 series,[1] and the PDP-6 and PDP-10 used two's complement, as did minicomputers such as the PDP-5 and PDP-8 and the PDP-11 and VAX. The architects of the early integrated circuit-based CPUs (Intel 8080, etc.) chose to use two's complement math. As IC technology advanced, virtually all adopted two's complement technology. x86,[2] m68k, Power Architecture,[3] MIPS, SPARC, ARM, Itanium, PA-RISC, and DEC Alpha processors are all two's complement.
; NOTE: of course, the address of the top and bottom of the stack and of the SP pointer could be converted to "signed array indices" for use by "bound" instruction …
%define USEABSOLUTEBOUNDS
%ifdef USEABSOLUTEBOUNDS
;mov word [boundlowerbound], 0 ; set [cannot-be-exceeded absolute] lower bound for "bound" instruction so that "iret" from "bound" instruction will not cause infinite loop …
mov word [boundlowerbound], -32767 ; set [cannot-be-exceeded absolute] lower bound for "bound" instruction so that "iret" from "bound" instruction will not cause infinite loop …
;mov word [boundupperbound], 32767 ; set [cannot-be-exceeded absolute] upper bound for "bound" instruction so that "iret" from "bound" instruction will not cause infinite loop …
mov word [boundupperbound], 65535 ; set [cannot-be-exceeded absolute] upper bound for "bound" instruction so that "iret" from "bound" instruction will not cause infinite loop …
%else
; globals boundlowerbound and boundupperbound can be kept for re-use by another "bound" instruction test, SP itself will not be changed, BP is "scratched" …
;mov word [boundlowerbound], BP-1 ; set [relatively lower] lower bound for "bound" instruction so that it will so that "iret" from "bound" instruction will not cause infinite loop …
;mov word [boundupperbound], BP+1 ; set [relatively lower] upper bound for "bound" instruction so that it will so that "iret" from "bound" instruction will not cause infinite loop …
mov word BP, [boundupperbound] – 1 ; set BP so that it will be [relatively lower] than upper bound for "bound" instruction so that it will so that "iret" from "bound" instruction will not cause infinite loop …
mov word BP, [boundlowerbound] + 1 ; set BP so that it will be [relatively higher] than lower bound for "bound" instruction so that it will so that "iret" from "bound" instruction will not cause infinite loop …
%endif ; USEABSOLUTEBOUNDS
; from http://en.wikipedia.org/wiki/16-bit
; A 16-bit integer can store 216 (or 65,536) distinct values. In an unsigned representation, these values are the integers between 0 and 65,535; using two's complement, possible values range from −32,768 to 32,767. Hence, a processor with 16-bit memory addresses can directly access 64 KiB of byte-addressable memory.
xor bl, bl
; mov byte bl, [stacktop – 4 * 2 + 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte bl, 'I' ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:90], bl ; 'I '
mov byte bl, 'N' ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:92], bl ; 'N '
mov byte bl, 'T' ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:94], bl ; 'T '
mov byte bl, '5' ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:96], bl ; '5 '
mov al, [interrupt5count]
mov DI, 100 ; screen position to print out character
call out2hex
mov al, [numberofpushrequired]
mov DI, 104 ; screen position to print out character
call out2hex
;OUT2HEXMACRO 100
; from Programmer's Reference Manual
; IRET (Return From Interrupt) returns control to an interrupted procedure. IRET differs from RET in that it also pops the flags from the stack into the flags register. The flags are stored on the stack by the interrupt mechanism.
;ret
iret
;%endmacro ; SAFEINT5
;%macro SAFEINT9 0
; my/your own custom interrupt 9 service routine
safeinterrupt9sr:
add byte [interrupt9count], 1
xor bl, bl
; mov byte bl, [stacktop – 4 * 2 + 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte bl, 'I' ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:110], bl ; 'I '
mov byte bl, 'N' ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:112], bl ; 'N '
mov byte bl, 'T' ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:114], bl ; 'T '
mov byte bl, '9' ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:116], bl ; '9 '
mov al, [interrupt9count]
mov DI, 120 ; screen position to print out character
call out2hex
;OUT2HEXMACRO 120
call safeinterrupt9sr2
; from Programmer's Reference Manual
; IRET (Return From Interrupt) returns control to an interrupted procedure. IRET differs from RET in that it also pops the flags from the stack into the flags register. The flags are stored on the stack by the interrupt mechanism.
;ret
iret
;%endmacro ; SAFEINT9
;%macro SAFEINT9 0
;keyboard input …
;for the screen, the messages in ("muo^n loa`i" “I read all of Intel x86(32bit) programmers manual, but did not found the magic number 0x7C00.”
;Yes. ”0x7C00 is NOT related to x86 CPU” . It’s natural that you couldn’t find out it in cpu specifications from intel. Then, you wonder, “Who decided it ?”
;”2nd” , you may wonder:
;>”0x7C00 is 32KiB – 1024B at decimal number. What’s this number means ?”
;Anyone decided it. But, why he/she decided such a halfway address?
;Hum…There’re TWO questions(mysteries) arround the magic number “0x7C00”.
;+ Who decided “0x7C00” ?
;+ What “0x7C00 = 32KiB – 1024B” means ?
;Okay, let’s dive into the secret of BIOS for “IBM PC 5150”, ancestor of modern x86(32bit) PCs, with me…!!
;#more||
;* “0x7C00″ First appeared in IBM PC 5150 ROM BIOS INT 19h handler.
;Wandering arround the history of x86 IBM Compatible PC, you know ”IBM PC 5150” is the ancestor of modern x86(32bit) IBM PC/AT Compatible PCs.
;This PC was released at 1981 August, with Intel 8088(16bit) and 16KiB RAM(for minimum memory model). BIOS and Microsoft BASIC was stored in ROM.
;When power on, BIOS processes “POST”(Power On Self Test) procedure, and after, ”call INT 19h” .
;In INT 19h handler, BIOS checks that PC has any of floppy/hard/fixed diskette or not have.
;If PC has any of available diskkete, BIOS loads a first sector(512B) of diskette into 0x7C00.
;Now, you understand why you couldn’t find out this magic number in x86 documents. ”This magic number belongs to BIOS specification.”
;* The origin of 0x7C00
;Stories surrounding IBM PC DOS, Microsoft, and SCP’s 86-DOS are famous stories. See: [[“A Short History of MS-DOS”>http://www.patersontech.com/dos/Byte/History.html%5D%5D.
;SCP’s “86-DOS”(at 1980) is the reference OS for IBM PC DOS 1.0.
;86-DOS(early called “QDOS”) is CP/M compatible OS for 8086/8088 cpu. At 1979, Digital Research Inc didn’t have developed CP/M for 8086/8088 cpu yet.
;SCP sold two S-100 bus board, one is 8086 CPU board, two is “CPU Monitor” rom board.
;”CPU Monitor” program provided bootloader and debugger. ”This “CPU Monitor” bootloader loaded MBR into “0x200”, NOT “0x7C00″” . In 1981, IBM PC DOS was the NEXT CP/M like OS for 8086/8088.
;So, I told you that “0x7C00 ”FIRST appeared” in IBM PC 5150 ROM BIOS”.
;Previous one, SCP’s CPU Monitor bootloader loads into 0x200, not 0x7C00.
;** Why that CPU Monitor’s bootloader loeded MBR into “0x200” ?
;There’re THREE reasons about “0x200”.
;+ 8086 Interrupts Vector use 0x0 – 0x3FF.
;+ 86-DOS was loaded from 0x400.
;+ 86-DOS didn’t use interrupts vectors between 0x200 – 0x3FF.
;These reasons mean 0x200 – 0x3FF needed to be reserved and couldn’t be in the way of an OS, no matter where 86-DOS or user application wanted to load.
;So Tim Paterson (86-DOS developer) chose 0x200 for MBR load address.
;* Q:Who decided “0x7C00″ ? – A: IBM PC 5150 BIOS Developer Team.
;”0x7C00” was decided by IBM PC 5150 BIOS developer team (Dr. David Bradley).
;As mentioned above, this magic number was born at 1981 and “IBM PC/AT Compat” PC/BIOS vendors did not change this value for BIOS and OS’s backward compatibility.
;Not Intel(8086/8088 vendor) nor Microsoft(OS vendor) decided it.
;* Q:What “0x7C00 = 32KiB – 1024B” means ? A: Affected by OS requirements and CPU memory layout.
;IBM PC 5150 minimum memory model had only 16KiB RAM. So, you may have a question.
;>”Could minimum memory model (16KiB) load OS from diskette ? BIOS loads MBR into 32KiB – 1024B address, but physical RAM is not enough…”
;No, that case was ”out of consideration” . One of IBM PC 5150 ROM BIOS Developer Team Members, Dr. David Bradley says:
;>”DOS 1.0 required a minimum of 32KB, so we weren’t concerned about attempting a boot in 16KB.”
;(Note: DOS 1.0 required 16KiB minimum ? or 32KiB ? I couldn’t find out which correct. But, at least, in 1981’s early BIOS development, they supposed that 32KiB is DOS minimum requirements.)
;BIOS developer team decided 0x7C00 because:
;+ They wanted to leave as much room as possible for the OS to load itself within the 32KiB.
;+ 8086/8088 used 0x0 – 0x3FF for interrupts vector, and BIOS data area was after it.
;+ The boot sector was 512 bytes, and stack/data area for boot program needed more 512 bytes.
;+ So, 0x7C00, the last 1024B of 32KiB was chosen.
;
;Once OS loaded and started, boot sector is never used until power reset. So, OS and application can use the last 1024B of 32KiB freely.
;After OS loaded, memory layout will be:
;#pre||>
;+——————— 0x0
;| Interrupts vectors
;+——————— 0x400
;| BIOS data area
;+——————— 0x5??
;| OS load area
;+——————— 0x7C00
;| Boot sector
;+——————— 0x7E00
;| Boot data/stack
;+——————— 0x7FFF
;| (not used)
;+——————— (…)
;||<
;That are the origin and reasons of "0x7C00", the magic number survived for about three decades in PC/AT Compat BIOS INT 19h handler.
;* References
;86-DOS related:
;- "8086 Monitor Instruction Manual"(MON 86 – V1.4)
;- "86-DOS(TM) User's Manual Version 0.3"
;- "86-DOS(TM) Programmer's Manual Version 0.3"
;- "86-DOS(TM) Instruction Manual Version ??"
;IBM PC 5150 related:
;- "IBM Personal Computer Hardware Reference Library", "Technical Reference" (IBM Personal Computer Technical Reference manual)
;- "IBM Personal Computer XT Hardware Reference Library", "Technical Reference" (IBM Personal Computer XT Technical Reference manual)
;Intel 8086/8088 data sheets:
;- "8086 16-BIT HMOS MICROPROCESSOR"
;- "M80C86/M80C86-2 16-BIT CHMOS MICROPROCESSOR"
;- "8088 8-BIT HMOS MICROPROCESSOR"
;CP/M related:
;- The Unofficial CP/M Web Site
;– http://www.cpm.z80.de/
;- CP/M Internals : Oscar Vermeulen Personal Web Site
;– http://www.dcast.vbox.co.uk/cpm.html
;- Digital Research – CP/M
;– http://www.digitalresearch.biz/CPM.HTM
;- CP/M Main Page
;– http://www.seasip.demon.co.uk/Cpm/
;86-DOS related:
;- Origins of DOS – Paterson Technology
;– http://www.patersontech.com/dos/
;- 86-DOS Resource Website
;– http://www.86dos.org/index.htm
;- DosMan Drivel
;– http://dosmandrivel.blogspot.com/
;And all related Wikipedia pages.
;* Special Thanks To…
;Special Thanks To:
;- Tim Peterson
;- David Bradley
;for japanese article, see:
;"Assembler/なぜx86ではMBRが"0x7C00"にロードされるのか?(完全版)"
;http://www.glamenv-septzen.net/view/614
;NOTE:
; from arpaci dusseau http://pages.cs.wisc.edu/~remzi/OSTEP/vm-segmentation.pdf
;an idea was born, and it is called segmenta-
;tion. It is quite an old idea, going at least as far back as the very early
;1960’s [H61, G62]. The idea is simple: instead of having just one base
;and bounds pair in our MMU, why not have a base and bounds pair per
;logical segment of the address space?
;[G62] “Fact Segmentation”
;M. N. Greenfield
;Proceedings of the SJCC, Volume 21, May 1962
;Another early paper on segmentation; so early that it has no references to other work.
;[H61] “Program Organization and Record Keeping for Dynamic Storage”
;A. W. Holt
;Communications of the ACM, Volume 4, Issue 10, October 1961
;An incredibly early and difficult to read paper about segmentation and some of its uses.
; from http://en.wikipedia.org/wiki/THE_multiprogramming_system
; The THE multiprogramming system was a computer operating system designed by a team led by Edsger W. Dijkstra, described in monographs in 1965-66[1] and published in 1968.[2] Dijkstra never named the system; "THE" is simply the abbreviation of "Technische Hogeschool Eindhoven", then the name (in Dutch) of the Eindhoven University of Technology of the Netherlands. The THE system was primarily a batch system[3] that supported multitasking; it was not designed as a multi-user operating system. It was much like the SDS 940, but "the set of processes in the THE system was static".[3]
;The THE system apparently introduced the first forms of software-based memory segmentation (the Electrologica X8 did not support hardware-based memory management),[3] freeing programmers from being forced to use actual physical locations on the drum memory. It did this by using a modified ALGOL compiler (the only programming language supported by Dijkstra's system) to "automatically generate calls to system routines, which made sure the requested information was in memory, swapping if necessary".[3]
; from NASM manual:
;NASM gives special treatment to symbols beginning with a period. A label beginning with a single period is treated as a local label, which means that it is associated with the previous non-local label. So, for example:
;label1 ; some code
;.loop
; ; some more code
; jne .loop
; ret
;label2 ; some code
;.loop
; ; some more code
; jne .loop
; ret
;In the above code fragment, each JNE instruction jumps to the line immediately before it, because the two definitions of .loop are kept separate by virtue of each being associated with the previous non-local label.
;from http://wiki.osdev.org/Interrupts
; if IRQ 6 is sent to the PIC by a device, the PIC would tell the CPU to service INT 0Eh, which presumably has code for interacting with whatever device sent the interrupt in the first place. Of course, there can be trouble when two or more devices share an IRQ; if you wonder how this works, check out Plug and Play.
; from http://www.techmasala.com/2006/03/31/foundation-stone-3-bios-part-2-the-interrupt-vector-table/:
;Foundation stone #3 – BIOS part 2 – The interrupt vector table
;by Ramesh on Friday,March 31, 2006 @ 9:50 am
;In my post Foundation stone #2 we saw that BIOS is the one that takes in charge when you switch on your PC. After collecting the inventory of available and properly working hardware, the BIOS sets up what is called as the Interrupts area. An interrupt is a signal to the processor that there is something that needs its attention. As such each and every piece of hardware that is put together in your PC is useless unless it is orchestrated well. Take for example the keyboard, if the attention is not given at the right time when you press a key and reciprocated accordingly wherever you are then you can call the thing that is sitting in front of you as dumb
;So when the BIOS is done with the inventory of hardware, it initializes a memory space of 1024 bytes starting at 0000:0000h (this is a representation of memory location in the form of segment:offset in hexadecimal). An interrupt is a small routine or code that has the necessary details of the interrupt and occupies 4 bytes. So starting at memory location 0000:0000h interrupts are stored. So a total of 256 interrupts can be stored in a the allotted 1024 bytes but all is not being initialized by the BIOS. There are different types of interrupts, hardware interrupts, software interrupts, user interrupts and so on. The BIOS fills up the hardware interrupts and the software interrupts are mostly added by the OS.
;The Interrupt Vector Table (IVT) is a mapping of the interrupt number and the memory location in the form of segment:offset. This memory location contains the interrupt code for that particular interrupt. It is the responsibility of the OS to keep track of the IVT and monitor for interrupt and notify the processor. So what happens when you press a key or release a key, the keyboard send signals that contain information on what key was pressed or released. This gets stored in the memory location assigned for the keyboard interrupt (traditionally interrupt 09h is for keyboard). The OS which is constantly looking for these interrupts immediately captures the information and sends it for processing accordingly. The interrupt number and other details could differ from one BIOS manufacturer to other. You can get a lot of information about BIOS and interrupts from the BIOS central site.
; conventionally [c.f. http://en.wikipedia.org/wiki/Conventional_memory, http://en.wikipedia.org/wiki/Power-on_self-test%5D people agree upon the following memory map … from http://www.supernovah.com/Tutorials/Assembly2.php:
;Default Memory
;When the computer boots, the BIOS loads the memory with a lot of different data. This data resides in different places throughout memory and we are only left with 630Kb of memory to work with in the middle of everything. Here is a table showing the map of the memory directly after the computer boots:
;All ranges are inclusive
;Address Range (in hex) Size Type Description
;0 – 3FF 1Kb Ram Real Mode Interrupt Vector Table (IVT)
;400 – 4FF 256 bytes Ram BIOS Data Area (BDA)
;500 – 9FBFF 630Kb Ram Free Memory
;9FC00 – 9FFFF 1Kb Ram Extended BIOS Area (EBDA)
;A0000 – BFFFF 128Kb Video Ram VGA Frame Buffer
;C0000 – C7FFF 32Kb Rom Video Bios
;C8000 – EFFFF 160kb Rom Misc.
;F0000 – FFFFF 64Kb
; from NASM manual
;Multi-line macros are much more like the type of macro seen in MASM and TASM: a multi-line macro definition in NASM looks something like this.
;%macro prologue 1
; push ebp
; mov ebp,esp
; sub esp,%1
;%endmacro
; from http://www.husseinsspace.com/teaching/udw/1996/asmnotes/chaptwo.htm:
;The SHR/SLR instructions
;format:
;SHR destination,1
;SHR destination,CL
; SHL destination,1
; SHL destination,CL
;SHR shifts the destination right bitwise either 1 position or a number of positions determined by the current value of the CL register. SHL shifts the destination left bitwise either 1 position or a number of positions determined by the current value of the CL register. The vacant positions are filled by zeros.
;example:
;shr ax,1
; shl ax,1
;The first example effectively divides ax by 2 and the second example effectively multiplies ax by 2. These commands are faster than using DIV and MUL for arithmetic involving powers of 2.
;****************************
; from Intel Programmer's Reference Manual
;10.1 Processor State After Reset
;The contents of EAX depend upon the results of the power-up self test. The self-test may be requested externally by assertion of BUSY# at the end of RESET. The EAX register holds zero if the 80386 passed the test. A nonzero value in EAX after self-test indicates that the particular 80386 unit is faulty. If the self-test is not requested, the contents of EAX after RESET is undefined.
;DX holds a component identifier and revision number after RESET as Figure 10-1 illustrates. DH contains 3, which indicates an 80386 component. DL contains a unique identifier of the revision level.
;Control register zero (CR0) contains the values shown in Figure 10-2 . The ET bit of CR0 is set if an 80387 is present in the configuration (according to the state of the ERROR# pin after RESET). If ET is reset, the configuration either contains an 80287 or does not contain a coprocessor. A software test is required to distinguish between these latter two possibilities.
;The remaining registers and flags are set as follows:
; EFLAGS =00000002H
; IP =0000FFF0H
; CS selector =000H
; DS selector =0000H
; ES selector =0000H
; SS selector =0000H
; FS selector =0000H
; GS selector =0000H
; IDTR:
; base =0
; limit =03FFH
;All registers not mentioned above are undefined.
;These settings imply that the processor begins in real-address mode with interrupts disabled.
;10.2 Software Initialization for Real-Address Mode
;In real-address mode a few structures must be initialized before a program can take advantage of all the features available in this mode.
;10.2.1 Stack
;No instructions that use the stack can be used until the stack-segment register (SS) has been loaded. SS must point to an area in RAM.
;10.2.2 Interrupt Table
;The initial state of the 80386 leaves interrupts disabled; however, the processor will still attempt to access the interrupt table if an exception or nonmaskable interrupt (NMI) occurs. Initialization software should take one of the following actions: Change the limit value in the IDTR to zero. This will cause a shutdown if an exception or nonmaskable interrupt occurs. (Refer to the 80386 Hardware Reference Manual to see how shutdown is signalled externally.)
; Put pointers to valid interrupt handlers in all positions of the interrupt table that might be used by exceptions or interrupts.
; Change the IDTR to point to a valid interrupt table.
;
;10.2.3 First Instructions
;After RESET, address lines A{31-20} are automatically asserted for instruction fetches. This fact, together with the initial values of CS:IP, causes instruction execution to begin at physical address FFFFFFF0H. Near (intrasegment) forms of control transfer instructions may be used to pass control to other addresses in the upper 64K bytes of the address space. The first far (intersegment) JMP or CALL instruction causes A{31-20} to drop low, and the 80386 continues executing instructions in the lower one megabyte of physical memory. This automatic assertion of address lines A{31-20} allows systems designers to use a ROM at the high end of the address space to initialize the system.
; from http://en.wikipedia.org/wiki/Interrupt_descriptor_table
;In the 8086 processor, the IDT resides at a fixed location in memory from address 0x0000 to 0x03ff, and consists of 256 four-byte real mode pointers (256 × 4 = 1024 bytes of memory). In the 80286 and later, the size and locations of the IDT can be changed in the same way as it is done in protected mode, though it does not change the format of it. A real mode pointer is defined as a 16-bit segment address and a 16-bit offset into that segment. A segment address is expanded internally by the processor to 20 bits thus limiting real mode interrupt handlers to the first 1 megabyte of addressable memory. The first 32 vectors are reserved for the processor's internal exceptions, and hardware interrupts may be mapped to any of the vectors by way of a programmable interrupt controller.
; A commonly used x86 real mode interrupt is INT 10, the Video BIOS code to handle primitive screen drawing functions such as pixel drawing and changing the screen resolution.
; from http://software.intel.com/en-us/articles/introduction-to-x64-assembly
; XOR EAX, EAX ; zero out eax
; MOV ECX, 10 ; loop 10 times
;Label: ; this is a label in assembly
; INX EAX ; increment eax
; LOOP Label ; decrement ECX, loop if not 0
; from https://courses.engr.illinois.edu/ece390/books/artofasm/CH06/CH06-5.html#HEADING5-294
; mov ecx, 255
;ArrayLp: mov Array[ecx], cl
; loop ArrayLp
; mov Array[0], 0
;The last instruction is necessary because the loop does not repeat when cx is zero. Therefore, the last element of the array that this loop processes is Array[1], hence the last instruction.
; The loop instruction does not affect any flags.
; 2.17.2014 chu' Ha^n telephoned about obtaining literature on American Philosophy and on US Census Data particularly
; US Census Data on black population expansion into US and into the world …
; following day: couple resembling co^ Be^ and David Lowe seen at Post Office when we tried to mail chu' Kha's preserved fruit to father in Michigan
; from http://randomascii.wordpress.com/2012/12/29/the-surprising-subtleties-of-zeroing-a-register/
; also see http://navet.ics.hawaii.edu/~casanova/courses/ics312_spring14/slides/ics312_bits_2.pdf
;Tabula rasa
;The x86 instruction set does not have a special purpose instruction for zeroing a register. An obvious way of dealing with this would be to move a constant zero into the register, like this:
;mov eax, 0
;That works, and it is fast. Benchmarking this will typically show that it has a latency of one Sandybridge diecycle the result can be used in a subsequent instruction on the next cycle. Benchmarking will also show that this has a throughput of three-per-cycle. The Sandybridge documentation says that this is the maximum integer throughput possible, and yet we can do better.
;Its too big
;The x86 instruction used to load a constant value such as zero into eax consists of a one-byte opcode (0xB8) and the constant to be loaded. The problem, in this scenario, is that eax is a 32-bit register, so the constant is 32-bits, so we end up with a five-byte instruction:
;B8 00 00 00 00 mov eax, 0
;Instruction size does not directly affect performance you can create lots of benchmarks that will prove that it is harmless but in most real programs the size of the code does have an effect on performance. The cost is extremely difficult to measure, but it appears that instruction-cache misses cost 10% or more of performance on many real programs. All else being equal, reducing instruction sizes will reduce i-cache misses, and therefore improve performance to some unknown degree.
;Smaller alternatives
;Many RISC architectures have a zero register in order to optimize this particular case, but x86 does not. The recommended alternative for years has been to use xor eax, eax. Any register exclusive ored with itself gives zero, and this instruction is just two bytes long:
;33 C0 xor eax, eax
;Careful micro-benchmarking will show that this instruction has the same one-cycle latency and three-per-cycle throughput of mov eax, 0 and it is 60% smaller (and recommended by Intel), so all is well.
;Suspicious minds
;If you really understand how CPUs work then you should be concerned with possible problems with using xor eax, eax to zero the eax register. One of the main limitations on CPU performance is data dependencies. While a Sandybridge processor can potentially execute three integer instructions on each cycle, in practice its performance tends to be lower because most instructions depend on the results of previous instructions, and are therefore serialized. The xor eax, eax instruction is at risk for such serialization because it uses eax as an input. Therefore it cannot (in theory) execute until the last instruction that wrote to eax completes. For example, consider this code fragment below:
;1: add eax, 1
;2: mov ebx, eax
;3: xor eax, eax
;4: add eax, ecx
;Careful micro-benchmarking will show that this instruction has the same one-cycle latency and three-per-cycle throughput of mov eax, 0 and it is 60% smaller (and recommended by Intel), so all is well.
;Ideally we would like our awesome out-of-order processor to execute instructions 1 and 3 in parallel. There is a literal data dependency between them, but a sufficiently advanced processor could detect that this dependency is artificial. The result of the xor instruction doesnt depend on the value of eax, it will always be zero.
;It turns out that for x86 processors have for years handled xor of a register with itself specially. Every out-of-order Intel and AMD processor that I am aware of can detect that there is not really a data dependency and it can execute instructions 1 and 3 in parallel. Which is great. The CPUs use register renaming to create a new eax for the sequence of instructions starting with instruction 3.
; from http://stackoverflow.com/questions/4909563/why-should-code-be-aligned-to-even-address-boundaries-on-x86
;Because the (16 bit) processor can fetch values from memory only at even addresses, due to its particular layout: it is divided in two "banks" of 1 byte each, so half of the data bus is connected to the first bank and the other half to the other bank. Now, suppose these banks are aligned (as in my picture), the processor can fetch values that are on the same "row".
; bank 1 bank 2
;+——–+——–+
;| 8 bit | 8 bit |
;+——–+——–+
;| | |
;+——–+——–+
;| 4 | 5 | >> dENarixs OS Project
;UIN: 30796163
; from http://devdocs.inightmare.org/x86-assembly-changing-interrupt-vector-table/
;(x86 Assembly) Changing Interrupt Vector Table
;(This tutorial was originally written in 2004 and featured in http://asm.inightmare.org/)
;Another thing I want to write tutorial is about changing interrupts. There are two ways you can do that using DOS interrupts and modifying interrupt vector table directly. Both ways are pretty simple, you need to know these DOS interrupts (int 21h):
;Function
;What does it do?
;Parameters
;AH = 25h Set interrupt vector AL – interrupt number to change
; DS:DX – pointer to interrupt function
;AH = 35h Get interrupt vector. Gets address of currently set interrupt. AL – interrupt number
; Returns:
; ES:BX – pointer to interrupt
;AH = 4Ch Exits DOS program 😉 AL – exit code (not sure what it does)
;It’s pretty simple, just take a look at the sample code here.
;The other way to make your own interrupt is to modify interrupt vector table directly. It’s mapped from 0000:0000 to 0000:0400h in memory. The structure is very simple:
;Offset
;Segment
;Int 0
;(Offset 0000)
;(Offset 0002)
;Int 1
;(Offset 0004)
;(Offset 0006)
;Int 2
;(Offset 0008)
;(Offset 0010)
;…
;…
;So getting interrupt offset is:
;mov ax, [intnum*4]
;And segment:
;mov ax [intnum*4+2]
;Setting:
;mov ax, [intnum*4] ; offset
;mov ax [intnum*4+2] ; segment
;Well and how to call the interrupt, I think we all know:
;int intnum
;Everything is pretty simple. NASM source code:
;DOS interrupt version – here
; Direct modifiying of intvec table – here
; from http://asm.inightmare.org/ints_vec.asm
; org 100h
;xor ax, ax
;mov es, ax
; Save interrupt address so we can restore it later
;mov bx, [es:69h*4]
;mov [old_int_off], bx
;mov bx, [es:69h*4+2]
;mov [old_int_seg], bx
; modify interrupt vector table on 0x69th entry to point to our interrupt
;mov dx, int_prog
;mov [es:69h*4], dx
;mov ax, cs
;mov [es:69h*4+2], ax
;nop
;int 69h ; execute our interrupt
;restore old interrupt
;mov ax, [old_int_seg]
;mov [es:69h*4+2], ax
;mov dx, [old_int_off]
;mov [es:69h*4], dx
;mov ax, 0x4c00 ; Exit
;int 21h
; Our interrupt just prints some text 🙂
;int_prog:
;pusha ; save old registers, just incase 😉
;mov ah, 9
;mov dx, our_text
;int 21h
;popa
;iret
;our_text db “Bleh… $”
;old_int_seg dw 0
;old_int_off dw 0
; from http://www.ece.msstate.edu/~janem/ECE3724/S03/Presentations/number_io.ppt
;This is the html version of the file http://www.ece.msstate.edu/~janem/ECE3724/S03/Presentations/number_io.ppt.
;Google automatically generates html versions of documents as we crawl the web.
;1
;Ways to Handle I/O (Input/Ouput)
;•For Output
;◦Use Irvine16 Functions
;◾Writechar, WriteBin, WriteInt, Writehex, Writestring
;◦Use DOS (Int 21h) Functions – (Table C-2)
;◾2 – write char, 6 – write char, 9- write string (Table C-3)
;◦Use Video BIOS (Int 10h) Functions
;◾9 – write char and attribute, 0A- write char, …
;•For Input
;◦Use Irvine16 Functions
;◾Readchar, Readint, ReadHex, Readstring
;◦Use DOS (Int 21h) Functions (Table C-2)
;◾1 – read char, 6 – read char, 7- read char
;◦Use Keyboard BIOS (Int 16h) Functions (Table C-5)
;◾10 – wait for key
;2
;Input/Output of Numbers
;•A common task is to input or output numbers in ASCII format
;•Output tasks:
;◦Output an 8-bit value as ASCII string in HEX format
;◦Output an 8-bit value as a ASCII string in BINARY format (see ‘pbin.asm’ example on WWW page)
;◦Output an 8-bit value as ASCII string in DECIMAL format
;•Input tasks:
;◦Input a string representing an 8-bit number in Hex format
;◦Input a string representing an two digit decimal number (unsigned)
;
;3
;Output an 8 bit number in Hex Format
;•Two Hex characters in 8-bits. Want to work with each set of 4-bits individually.
;•Each Hex character represents 4-bits in a number.
;◦0000 = ‘0’ (ASCII code = 30h)
;◦0001 = ‘1’ (ASCII code = 31h)
;◦1001 = ‘9’ (ASCII code = 39h)
;◦……
;◦1010 = ‘A’ (ASCII code = 41h)
;◦1011 = ‘B’ (ASCII code = 42h)
;◦……
;◦1111 = ‘F’ (ASCII code) = 46h ).
;•If 4-bits is between 0-9, then ASCII = 30h + 4bits
;•If 4-bits is between A-F, then ASCII = 37h + 4bits
;4
;Output an 8 bit number in Hex Format
;Approach: Write a subroutine called ‘Out1Hex’. This will output the lower 4 bits of register ‘AL’ as an Hex digit to the screen.
;To output an 8-bit value, the main routine(out2hex) will call ‘Out1Hex’ twice 1) for the most significant HEX digit, and
; 2) for the least significant Hex digit.
; out2hex proc
;; output value in ‘al’ as 2 hex character
; push ax ; save al
; shr al, 4 ; get most sig. 4 bits into lower
; call Out1Hex ; print most sig. hex digit
; pop ax ; get back original al
; and al, 0x0Fh ; upper 4 bits = 0 – working with low 4 bits
; call Out1Hex ; print least sig. hex digit
; out2hex endp
;5
;Out1Hex
;Pseudo code for Out1Hex:
;
; if ( AL > 09H) jump to SKIP
; AL = AL + 30H
; Use Int21H, function2 to print character
; return
;
; skip: AL = AL + 37H
; Use Int21H, function2 to print character
; return
;
;
;6
; from Programmer’s Reference Manual
; CMP (Compare) subtracts the source operand from the destination operand. It updates OF, SF, ZF, AF, PF, and CF but does not alter the source and destination operands. A subsequent Jcc or SETcc instruction can test the appropriate flags.
; from
;Out1Hex
;A procedure to convert a 4-bit hex number to ASCII and print the character to the screen.
;Out1hex proc
;Cmp al, 9 ;is 4-bit value above 9?
;Ja ischar ;if so, must be a character
;Add al, 30h ;if not, add 30h for conversion
;Jmp printit ;go to print label
;Ischar: add al, 37h ;was character – add 37h for ;conversion
;Printit: mov dl, al ;printing a character to screen
;Mov ah,2 ;using int 21h, function 2.
;Int 21h
;Ret ;return to main procedure
;Out1hex endp
;End Main
;7
;Output a 16-bit hex number? 32 bits?
;•How would you print out a 16 bit value?
;◦Call Out1Hex 4 times.
;◦Each call would have to have the 4 bits in the lower four bits of AL
;◦You would have to start with the Most significant bits
;◦After saving the value, use shr instruction to get the correct bits.
;•How would you printout a 32-bit value?
;◦Call ‘Out1Hex’ 8 times – once for each 4 bits of the 32-bit value.
;8
;Output an 8-bit number in Decimal Format
;•How would you output a number in Decimal format?
;•Assume that AL contains a value between 0 and 99 and you want to print this out as a decimal value
;•The value of the first digit is ‘AL divided by 10’ (quotient value of AL/10).
;•The value of the 2nd digit is REMAINDER of AL divided by 10!!
;9
;Out1Dec
;A procedure to convert an 8-bit unsigned decimal number stored in AL to ASCII and print the character to the screen.
;Out1Dec Proc
;Push ax ;save value
;And ah, ah ;clear ah
;Div 10 ;divide value by 10 (quotient in AL, ;remainder in AH)
;Add al, 30h ;convert 10’s digit to ASCII
;Call printchar
;Mov al, ah ;get 1’s digit
;Add al, 30h ;convert to ASCII
;Call printchar
;Out1Dec Endp
;10
;Input an 8-bit number in HEX format
;•An 8-bit hex number will require two ASCII characters to represent it
;•Need to get 4-bit value of digit from ASCII character code
;•If ASCII is between 30H and 39H (‘0’ and ‘9’), then four-bit value is ASCII value – 30H.
;•If ASCII is between 41H and 46H (‘A’ and ‘F’), then four-bit value is ASCII value – 37H
;11
;Input an 8-bit number in HEX format
;Assume AX has the two ASCII digits that represent a HEX number
;Example: AX = 4335 h, AH = 43h = ‘C’, AL=35h = ‘5’.
;Want to convert this to AL = C5h.
; in2hex proc
; push ax ;; save AX
; mov al,ah ;; get most sig. char into AL
; call inhex ;; convert ASCII hex code in AL to 4 bit value
; mov bl, al ;; save in BL
; pop ax ;; get AX back
; call inhex ;; convert ASCII hex code in AL to 4-bit value
; shl bl,4 ;; shift bl to left to move lower 4bit to upper
; or al, bl ;; combine upper and lower bits, AL has value!
; ret
; in2hex endp
;12
;inhex Subroutine
;Want to convert the ASCII code in AL that is a HEX digit to its 4-bit value
; Pseudo code: if (AL > 39h) jump to skip
; AL = AL – 30h
; return
; skip: AL = AL – 37H
; return
;13
;Input an 8-bit number in Decimal format
;Assume AX has the two ASCII digits that represent a DECIMAL number
;Example: AX = 3731 h, AH = 38h = ‘7’, AL=31h = ‘1’.
;Want to convert this to AL = 71 (decimal) = 47h !!
; Approach:
; a. Convert the most significant ASCII digit to its four bit value.
; b. Multiply this by 10 and save.
; c. Convert the least significant ASCII digit to its four bit value and ADD it to the value produced in ‘b’!!
; 71 = 7 * 10 + 1 = 71 = 47 h.
3.21.2014
3/21/2014
thanh ~ green ~ blue ~ xanh [hulk on gia ba?o’ “lunch box” and at nursery or elsewhere] so+n’s birthday today … di` ba visit gia ba?o and is requested a present for gia ba?o’s father … : lots of heineken at 99 ranch … –where sesame sweet was bought for father … fat is the price of the protein– … bought some from safeway … and yogurt and bread … whence father telephoned among pt cruisers about money …

order to go macdonald lunch at home with ddi.nh and die^~m after she went to hospital for routine exam …







gia ba?o’s “mcherrie” … … Xua^n Mai “Em DDi Chu`a Hu+o+ng” …
lots of hindu-ish champa cha`m people in ba.c lie^u region …
fire and explosion on local tv news … at plant and school and grass plots ..
yesterday viettoday tv news mentions hindu spring festival … just in time for today vernal equinox …
from http://d4nations.com/webpubl/articles/holi-hindu-spring-festival.html
Holi is an Indian Hindu festival (on the Hindu calendar) which derives it’s roots from the worship of goddess Raka, the goddess of love and prosperity.
In Gujarat Holi spring festival is two day festival. On the evening of the first day people lit the bonfire.
People offer raw coconut, corn to the fire. The second day is the festival of colour or “Dhuleti”, celebrated by sprinkling coloured water and applying colours to each other.
There is a symbolic legend to explain why holi is celebrated. The word “Holi” originates from “Holika”, the evil sister of demon king Hiranyakashipu.
King Hiranyakashipu had earned a boon that made him virtually indestructible.
The special powers blinded him, he grew arrogant, felt he was God, and demanded that everyone worship only him.
Holi festival has other cultural significance. It is the festive day to end and rid oneself of past errors, end conflicts by meeting others, a day to forget and forgive. People pay or forgive debts, as well as deal anew with those in their lives.
Holi also marks the start of spring, and for many the start of new year.
Meanwhile, President Pranab Mukherjee, Prime Minister Manmohan Singh and UPA chairperson Sonia Gandhi wished India citizens a happy and safe Holi.
“May the festival bring health, happiness and prosperity to all,” Singh said.


![]()
“stops in the name of love, before you break my heart …” The Supremes … San Francisco …: to^nan was threatened by a car that accelerated suddendly at intersection before fermilab gate in batavia, il … Die^.p [who resembles co^ Hie^n chu’ Hu+ng] ran a stop sign in note 3.6.2014 … supposedly Ye^’n wants a mobile home or some place nearer to Le^ Duye^n II in San Jose because twice she felt sleepy while driving back home to Gia Ba?o in Dublin, California before midnight comes …



to^nan and family wish the people in Syria, in India, in Dubai and in all places on earth and “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well” …

syria earning/learning buddha’s [4/5/2014 and Islam’s] non-attachment …: blond russian child with bald-headed dark-skinned young man both with bloodshot eyes at safeway grocery … song “where is the love” .. show me the love … jewish immigration out of russia …
[4/5/2014 the broken water pipes and the mouse have decimated our basement library in much the same manner as last year summer storm in the Phillipines and tomorrow is Sunday church sermon day ….
Qur’an
Sura 102 – Acquisitiveness
In the name of God the Compassionate the Caring
Acquisitiveness turns you away
Until you reach the graves ~ gravity ~ gravitation ~ ta^m/trinity/conscience ~ ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’
Oh then you will know
Surely then you will know
Surely you will know with knowledge certain
You will see a blazing fire
Then you will see it with an eye certain
At that time then
you will be asked about true well-being ~ about ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’
~ * ~
the commentary goes: “As part of cultural training for those about to visit bedouin Arab societies, visitors are cautioned about complementing anyone on a possession, whether an engraved metal coffee pot, a precious rug, or a fine horse. The host might well say to the guest not ‘thank you’ but ‘it’s yours’ and insist the guest accept it.
This bedouin hospitality was a constant from pre-Islamic through Islamic times. In the pre-Islamic period it was associated with the generous hero, the Karim, who was willing to share all he had with his tribe, including his camel mare. The Qur’an kept the emphasis on generousity, but transferred the ideal of the Karim from tribal leader to the one God, and changed the mechanism of generosity from large tribal banquets to organized means of contributing to the poor. While denunciation of hoarding and acquisitiveness remained constant in pre-Islamic poetry and the Qur’an, the Qur’anic denunciations added a new theological twist. Those who spend their lives acquiring and hoarding possessions end up enslaved by those possessions and blinded by them to what ultimately matters ~ mass.”
from p. 114-115 “Approaching the Qur’an – the early revelations” introduced and translated by Michael Sells]


“mac daddy” or “dda.t” mentioned “dubai” or some such on bar outing …
if biblical “in the image” is true then how is dubai “in the image” of damascus one might wonder …: well, suppose that sand is the personal “soul” of arabia but now with high rises built by international laborers from phillipines–according to David Lowe … to^nan thought of how the old bedouin shepherd-sheep relationship could be transformed into arab-master-phillipine-labor-girl relationship that David Lowe related to him “she–the phillipine labor girl–cried saying she’s afraid of coming out onto the street because some arab master might drive by and kidnap/snatch her up …”… Tra^`n Tie^u’s “Con Tra^u”–, india etc. the sand “soul” has been transformed … perhaps people earn/learn that way what is the all-covering soul the bao or ba?o or all-soul or universal “soul” of “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well” …
father said o^ng le^~’s [le^. ~ tear ~ christ] sister passes …
“Sister Christian”
NIGHT RANGER LYRICS [shortly before judeo-christian millenium celebration]
Sister Christian
Oh, the time has come
And you know that you’re the only one
To say, okay
Where you going
What you looking for
You know those boys
Don’t want to play no more with you
It’s true
You’re motoring
What’s your price for flight
In finding mister right
You’ll be alright tonight
Babe, you know
You’re growing up so fast
And mama’s worrying
That you won’t last
To say, let’s play
Sister Christian
There’s so much in life
Don’t you give it up
Before your time is due
It’s true
It’s true, yeah
Motoring
What’s your price for flight
You’ve got him in your sight
And driving thru the night
Motoring
What’s your price for flight
In finding mister right
You’ll be alright tonight
[Instrumental Interlude]
Motoring
What’s your price for flight
In finding mister right
You’ll be alright tonight
Motoring
What’s your price for flight
In finding mister right
You’ll be alright tonight
Sister Christian
Oh, the time has come
And you know that you’re the only one
To say, okey
But you’re motoring
Yeaaaaah, motoring
http://www.azlyrics.com/lyrics/nightranger/sisterchristian.html
advertisement for movie “Gravity” on tv … TV show {co^ Be^ is coming} “Island Hunter” [a fragmented {ca^u chuye^.n bo’ ddu~a; segment:offset computer memory; ca^.u be’ ti’ hon grimm’s fairy tale or tom thumb} human world –destruction in damascus, syria while holi in india and construction in dubai … song that came on automatic on car radio on way to airport to california but got turned back due to missing papers was Người Thợ Săn Và Đàn Chim Nhỏ
Tác giả: Anh Bằng … at Target store today 3/24/2014 –seemingly could not help itself when it could easily have helped itself …; with application/example to the humanity of Hoa`ng Sa Tru+o+`ng Sa …
KENNY ROGERS LYRICS
“Islands In The Stream”
(feat. Dolly Parton)

![]()
3/24/2014 yesterday or day before di` ba showed what purportedly was ultrasound pictures of daliah “dolly” adorable …
Baby, when I met you
There was peace unknown
I set out to get you
With a fine tooth comb
I was soft inside
There was something going on
You do something to me
That I can’t explain
Hold me closer and I feel no pain
Every beat of my heart
We got something going on
Tender love is blind
It requires a dedication
All this love we feel
Needs no conversation
We can ride it together, ah-ha
Making love with each other, ah-ha
Islands in the stream
That is what we are
No one in between
How can we be wrong
Sail away with me
To another world
And we rely on each other, ah-ha
From one lover to another, ah-ha
I can’t live without you
If the love was gone
Everything is nothing
If you got no one
And you did walk in the night
Slowly losing sight of the real thing
But that won’t happen to us
And we got no doubt
Too deep in love and we got no way out
And the message is clear
This could be the year for the real thing
No more will you cry
Baby, I will hurt you never
We start and end as one
In love forever
We can ride it together, ah-ha
Making love with each other, ah-ha
Islands in the stream
That is what we are
No one in between
How can we be wrong
Sail away with me
To another world
And we rely on each other, ah-ha
From one lover to another, ah-ha
Sail away
[Instrumental Interlude]
Ooooh, come sail away with me
Islands in the stream
That is what we are
No one in between
How can we be wrong
Sail away with me
To another world
And we rely on each other, ah-ha
From one lover to another, ah-ha
Islands in the stream
That is what we are
No one in between
How can we be wrong
Sail away with me
To another world
And we rely on each other, ah-ha
From one lover to another, ah-ha
Writer(s): Adenair Luiz da Rocha Lima Dena, Sergio Carrer Feio, Barry Gibb
Copyright: Crompton Songs, Universal Music Publishing Int. Mgb Ltd.
http://www.azlyrics.com/lyrics/kennyrogers/islandsinthestream.html
] Phillipines and Australia …
This picture taken the United Nations Relief and Works Agency for Palestine Refugees in the Near East (UNRWA) shows residents of the besieged Palestinian camp of Yarmouk, queuing to receive food supplies, in Damascus, Syria, on January 31, 2014. A United Nations official is calling on warring sides in Syria to allow aid workers to resume distribution of food and medicine in a Palestinian district of Damascus. The call comes as U.N. Secretary General Ban Ki-Moon urged Syrian government to authorize more humanitarian staff to work inside the country, devastated by its 3-year-old conflict. (AP Photo/UNRWA)
from testNASM.asm:
; interrupts are a type of messages “muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”
; and the interrupt table [of outgoing becauses/answers/responses {do tha’i … } to incoming messages] is placed as close to the origin nguye^n thu?y 0x0:0x0 as possible with/by the BIOS
; girl immitating the suprememes pointing fingers on our trip to san francisco:
; I know, I know you must follow the sun
;Wherever it leads
;But remember
;If you should fall short of your desires
;Remember life holds for you one guarantee
;You’ll always have me
; And if you should miss my lovin
;One of these old days
;If you should ever miss the arms
;That used to hold you so close, or the lips
;That used to touch you so tenderly
;Just remember what I told you
;The day I set you free
;
;Ain’t no mountain high enough
;Ain’t no valley low enough
;Ain’t no river wild enough
;To keep me from you
; http://youtu.be/VqW2XigtDEU
; Glady Knights and the Pip–van wilder II peep/pip/nhi`nh/ and Charles dickens Great Expectation pip–Midnight Train to Georgia: note 2.9.2014 porn left la for the desert of las vegas …
; universal-loop
; {
; start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // in “gia ba?o”, “ba?o” ~ maintain as in “ba?o thu?/to^`n” …
; try/if ;// tin messages …. the try/if is the “gia” of “gia ba?o” …
; maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // the message “stack” is loaded or push-pop with messages …; // push-and-pop-or-sent-and-receive (&messageNEW-hay-tinLA`NH); // tin and shakespeare’s version of “all roads lead to rome”: “doubt thou the stars are fire doubt truth to be a liar but never doubt I loved ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well'”: 1/19/2014 Sunday Service … Gospel ~ Good News Tin La\nh …”Gia Ba?o”: the “gia” attempts to reach an agreement with the “ba?o” …// salinger on internet news: push/pop/create stack/heap by an expansion assignment (“muo^n loa`i” ; ;catch/else ;// unmaintainable tin/messages or kho’ tin hay kho^ng tin no messages … SBTN Uye^n Thi. commercial for MBR [master boot record] “kho’ tin nhu+ng co’ tha^.t …”
; ; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
; }








yesterday ddi.nh telephoned from work to die^~m … it sounds from a far in a muddle resembling “… it warns you from using evil magic …” [viettoday huye^`n tra^n interview daughter of forever beaumore; long ago before to^nan starts cleaning the carpets thanh so+n vacuum something and spewed out sparkles all over gia ba?o’s room … which must have signifies that the air registers needs filter etc. … song mr. sandman
song
one wonders if the force the japanese committed in china during wwii did not prod the chinese
pak-ming ho from hong kong introduces to^nan to kathleen battle “sinners don’t let this harvest past” –japanese soldiers and na.n ddo’i ma^’t mu`a in vietnam and china during wwii … and current prayer for rain in california– in batavia, il ….
into wishing –wishing is magic–and wishing is gravitation/sunlight because everything gravitates around/toward the wish and the wish would be the light/sunshine or the wish is the origin of light/sunshine– and what’s even more magical– more gravity/massive more light/sunshine– is automatic relieve/relief of suffering that doesn’t have to be wished [] for because “Gravity/Sun/Tro+`I sinh Gravity/Sun/Tro+`I du+o+~ng Gravity/Sun/God cares for even the fallen sparrow and the lilies of the field how much would Gravity/Sun/God cares for you …”–for an end of japanese occupation to the point of contributing indirectly–through magic–to hiroshima … to^nan and family wish the practical everyday universal gravity/magic/sunshine of “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well” …
] in connection to John Gardner’s novel “The sunlight dialogue” in note 3.1.2014 …
… 3/23/2014 window [windows computer operating system violates 10 commandments] sash inside metal tensioned “channel balance” is broken …
tensor analysis = Hiroshima and gravitation ~ Syria …
AMERICA LYRICS
“Sister Golden Hair”
Well I tried to make it Sunday, but I got so damn depressed
That I set my sights on Monday and I got myself undressed
I ain’t ready for the altar but I do agree there’s times
When a woman sure can be a friend of mine
Well, I keep on thinkin’ ’bout you, Sister Golden Hair surprise
And I just can’t live without you; can’t you see it in my eyes?
I been one poor correspondent, and I been too, too hard to find
But it doesn’t mean you ain’t been on my mind
Will you meet me in the middle, will you meet me in the air?
Will you love me just a little, just enough to show you care?
Well I tried to fake it, I don’t mind sayin’, I just can’t make it
Well, I keep on thinkin’ ’bout you, Sister Golden Hair surprise
And I just can’t live without you; can’t you see it in my eyes?
Now I been one poor correspondent, and I been too, too hard to find
But it doesn’t mean you ain’t been on my mind
Will you meet me in the middle, will you meet me in the air?
Will you love me just a little, just enough to show you care?
Well I tried to fake it, I don’t mind sayin’, I just can’t make it
Doo wop doo wop …
Writer(s): Gerry Beckley
Copyright: WB Music Corp.
http://www.azlyrics.com/lyrics/america/sistergoldenhair.html
holi: nguye^n thu?y loa`i ngu+o+`i is universal comraderie …
syria: nguye^n thu?y loa`i ngu+o+`i is universal home under the stars and sun …
safeway grocery: russian child hungering for love dancing with bald-headed dark-skinned dude with red eyes …: love immigrated from russia moon back to the holy land … arabia … and hasn’t been back to the moon since …
nguye^n thu?y loa`i ngu+o+`i is “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well” …
orchard hardware first time with mother … garden hose … die^~m di` ba said her water broke by a tablespoon and flowers and grill cleaners …. second time alone… coughing helper … drywall screw for an air register that has fiberglass literally oozing out of it above a carpet resembling fiber glass in the guest living room with the glass balls lamps in a recent porn … blue sexy india indian woman … california car hand wash … where when we first got here in note 1.30.2014 were in perfect synchronization to some vietnamese song on ddi.nh/die^~m’s cadillac …. by minh tuyet yeu mot nguoi song ben mot nguoi … on second browsing note that song number 5 is “chi? ca^`n anh tho^i” … see previous note about “show and tell” or “chi?” … ba’c Ca^`n telephoned about co^ Va^n falling and her shoulder bone came out [of its joint presumably] and is being rehabilitated [chiropractice presumably] … mother converse about dau ca^`n at supper … found picture frame with Paris Eiffel tower in garage with father and dr chen’s pictures …
yesterday when to^nan overstepped his boundary and suggested ye^’n to stay di` ba stepped in and closed the door … and media such as tv or radio or ipad/iphone says “can never be more than friend” along with “xin lo^~i” …

recall seeing an india indian woman at pho+? sa`igo`n yesterday as well as how through the restaurant window’s can be seen road sign advertising for “immersion preschool” and remember father’s story about his misconstrue or proper construe … car license plate “probity” or some such … the lab instruction “immerse in total” at Ford’s Central Lab and about to^nan fainting and waking up to the greek and plato and platonic relationship …

hardness: tap 350, culligan 12-14, refrigerator 350, crystal geyser bottled water 

http://www.yelp.com/biz/dent-extractors-hand-car-wash-dublin
http://www.ibtimes.co.in/articles/543601/20140317/holi-2014-festival-colours-gulal-photos-india.htm
********************************
Why Celebrate Holi?
The festival of Holi can be regarded as a celebration of the Colors of Unity & Brotherhood – an opportunity to forget all differences and indulge in unadulterated fun. It has traditionally been celebrated in high spirit without any distinction of cast, creed, color, race, status or sex. It is one occasion when sprinkling colored powder (‘gulal’) or colored water on each other breaks all barriers of discrimination so that everyone looks the same and universal brotherhood is reaffirmed. This is one simple reason to participate in this colorful festival. Let’s learn more about its history and significance…
What is ‘Phagwah’?
‘Phagwah’ is derived from the name of the Hindu month ‘Phalgun’, because it is on the full moon in the month of Phalgun that Holi is celebrated. The month of Phalgun ushers India in Spring when seeds sprout, flowers bloom and the country rises from winter’s slumber.
Meaning of ‘Holi’
‘Holi’ comes from the word ‘hola’, meaning to offer oblation or prayer to the Almighty as Thanksgiving for good harvest. Holi is celebrated every year to remind people that those who love God shall be saved and they who torture the devotee of God shall be reduced to ashes a la the mythical character Holika.
The Legend of Holika
Holi is also associated with the Puranic story of Holika, the sister of demon-king Hiranyakashipu. The demon-king punished his son, Prahlad in a variety of ways to denounce Lord Narayana. He failed in all his attempts. Finally, he asked his sister Holika to take Prahlad in her lap and enter a blazing fire. Holika had a boon to remain unburned even inside fire. Holika did her brother’s bidding. However, Holika’s boon ended by this act of supreme sin against the Lord’s devotee and was burnt to ashes. But Prahlad came out unharmed.
The Krishna Connection
Holi is also associated with the Divine Dance known as Raaslila staged by Lord Krishna for the benefit of his devotees of Vrindavan commonly known as Gopis.
http://hinduism.about.com/od/holifestivalofcolors/a/celebrateholi.htm
testNASM – interrupt mechanism
; boot.asm
; bin version
; song “I hope when you decide, kindness will be your guide …”:
; “I did not program you, you program you: cha me. sinh con tro+`i sinh ti’nh/compute/program:
; I program/vote/ba^`u{di` ba co^ Die^~m’s pregnancy}/wish/love/aim ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’, and
; Everything/All/Allah/Nature/God programs/votes/ba^`u{di` ba co^ die^~m’s pregnancy}/wishes/loves/aims/’muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’, and
; the rest, what’s in between God and I is you is up to you … hopefully you too will program along with God and I for
; ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ ….
;from NASM manual:
; The BITS directive specifies whether NASM should generate code designed to run on a processor operating in 16-bit mode, 32-bit mode or 64-bit mode.
; You do not need to specify BITS 32 merely in order to use 32-bit instructions in a 16-bit DOS program; if you do, the assembler will generate incorrect code because it will be writing code targeted at a 32-bit platform, to be run on a 16-bit one:
; When NASM is in BITS 16 mode, instructions which use 32-bit data are prefixed with an 0x66 byte, and those referring to 32-bit addresses have an 0x67 prefix. In BITS 32 mode, the reverse is true: 32-bit instructions require no prefixes, whereas instructions using 16-bit data need an 0x66 and those working on 16-bit addresses need an 0x67.
; When NASM is in BITS 64 mode, most instructions operate the same as they do for BITS 32 mode.
[BITS 16]
; from the Programmer’s Reference Manual
;The segment containing the currently executing sequence of instructions is known as the current code segment;
;it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using
;as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment
;control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.
;The instruction pointer register (EIP) contains the offset address, relative to the start of the current code
;segment, of the next sequential instruction to be executed. The instruction pointer is not directly visible
;to the programmer; it is controlled implicitly by control-transfer instructions, interrupts, and exceptions.
;As Figure 2-9 shows, the low-order 16 bits of EIP is named IP and can be used by the processor as a unit.
;This feature is useful when executing instructions designed for the 8086 and 80286 processors.
; from http://wiki.osdev.org/Babystep2:
; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
; of segment and offset that point to the same address.
; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
; of segment and offset that point to the same address. For instance, some say that the bootloader is is loaded at 0000:7C00,
; while others say 07C0:0000. This is in fact the same address: 16 * 0x0000 + 0x7C00 = 16 * 0x07C0 + 0x0000 = 0x7C00.
; It doesn’t matter if you use 0000:7c00 or 07c0:0000, but if you use ORG you need to be aware of what’s happening
; from http://www.supernovah.com/Tutorials/BootSector2.php:
;The BIOS does not load the boot sector to a random spot in memory. The BIOS will always load the boot sector starting at the memory location 0x7C00.
; from http://www.supernovah.com/Tutorials/BootSector2.php
;As stated earlier, we cannot be sure if the BIOS set us up with the starting address of 0x7C0:0x0 or 0x0:0x7C00.
;We will use the second segment offset pair to execute our boot sector so we know for sure how the CPU will access
;our code. To do this, our very first instruction will be a far jump that simply jumps to the next instruction.
;The trick is, if we specify a segment, even if it is 0x0, the jmp will be a far jump and the CS register will be
;loaded with the value 0x0 and the IP register will be loaded with the address of the next instruction to be
;executed.
;[BITS 16]
;[ORG 0x7C00]
;jmp 0x0:Start
;Start:
; This code will set the CS segment to 0x0, set the IP register to the the very next instruction which will be slightly past 0x7C00, ….
; universal-loop
; {
; start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // in “gia ba?o”, “ba?o” ~ maintain as in “ba?o thu?/to^`n” …
; try/if ;// tin messages …. the try/if is the “gia” of “gia ba?o” …
; maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // the message “stack” is loaded or push-pop with messages …; // push-and-pop-or-sent-and-receive (&messageNEW-hay-tinLA`NH); // tin and shakespeare’s version of “all roads lead to rome”: “doubt thou the stars are fire doubt truth to be a liar but never doubt I loved ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well'”: 1/19/2014 Sunday Service … Gospel ~ Good News Tin La\nh …”Gia Ba?o”: the “gia” attempts to reach an agreement with the “ba?o” …// salinger on internet news: push/pop/create stack/heap by an expansion assignment (“muo^n loa`i” ; ;catch/else ;// unmaintainable tin/messages or kho’ tin hay kho^ng tin no messages … SBTN Uye^n Thi. commercial for MBR [master boot record] “kho’ tin nhu+ng co’ tha^.t …”
; ; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
; }
; irish-catholic Pat Benatar song “heartbreaker, dreammaker, don’t you mess around with me …” ….
; perhaps “there’s beggary in a love that can be reckoned” when love is unconditional–gia ba?o chu’ hoa`ng to^n an hoa`ng phi hu`ng and 10 commandments–but
; the ten commandments say there’s a love that’s conditional … and the 10 commandments describe the limits or conditions of that love …
; from http://wiki.osdev.org/Babystep2:
;some say that the bootloader is loaded at [metaphorical address] 0000:7C00, while others say 07C0:0000.
;This is in fact the same [real] address: 16 * 0x0000 + 0x7C00 = 16 * 0x07C0 + 0x0000 = 0x7C00.
;%define ORIGIN ; ….. comment this out to use “org 0” instead of “org 0x07C0” …
; test segment:offset scheme
;%assign ORIGIN 0x0
;%assign ORIGIN 0x7c00
%assign ORIGIN 0x7990 ; 3/6/2014 home alone with mother …
;%ifdef ORIGIN
%if ORIGIN = 0x7c00
[ORG 0x7c00]
%define PROGRAMSEGMENT 0x0
;segment .text align=16
; segment:offset … ds:offset or cs:offset … 0:offset-from-0x7COO … that is, labels in code following is addressed as 0:0x7C00+offset-from-start-of-file
;Following code will set the CS segment to 0x0, set the IP register to the the very next instruction which will be slightly past 0x7C00, ….
jmp 0x0:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
;%else ;
%elif ORIGIN = 0x0
[ORG 0]
%define PROGRAMSEGMENT 0x07C0
;segment .text align=16
; segment:offset … ds:offset or cs:offset … 0x07C0:offset-from-0 … that is, labels in the code following is addressed as 0x07C0:0+offset-from-start-of-file
;Following code will set the CS segment to 0x07C0, set the IP register to the the very next instruction which will be slightly past 0x0, ….
jmp 0x07C0:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; from http://wiki.osdev.org/Babystep2:
; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
; of segment and offset that point to the same address.
; (0x07c00 – 0x07cf) / 0x10 = (7431) / 0x10 = 743.1
; (0x07c00 – 0x03e7) / 0x10 =
; (0x07c00 – 0x7990) / 0x10 = 0x0270 / 0x10 = 0x0027
; 31744 – 31120
%elif ORIGIN = 0x7990 ; grateful for hexadecimal conversion from http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html and hex calculator from http://www.miniwebtool.com/hex-calculator/?number1=270&operate=1&number2=7990
[ORG 0x7990]
%define PROGRAMSEGMENT 0x0027
;segment .text align=16
; segment:offset … ds:offset or cs:offset … 0x0027:offset-from-0x7990 … that is, labels in code following is addressed as 0:0x7990+offset-from-start-of-file
;Following code will set the CS segment to 0x0027, set the IP register to the the very next instruction which will be slightly past 0x7990, ….
jmp 0x0027:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
;%endif ; ORIGIN
%endif; ORIGIN
;%ifdef ORIGIN
%if ORIGIN = 0x7c00
%define MEMORYSEGMENTREALLOWBOUND 0x7C00 ; 31744
;%else
%elif ORIGIN = 0x0
%define MEMORYSEGMENTREALLOWBOUND 0x0000 ; 0
%elif ORIGIN = 0x7990 ; grateful for hexadecimal conversion from http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html and hex calculator from http://www.miniwebtool.com/hex-calculator/?number1=270&operate=1&number2=7990
%define MEMORYSEGMENTREALLOWBOUND 0x0027 ; 39
%endif ; ORIGIN
%define SEGMENTSIZE 512
%define MEMORYSEGMENTREALUPPERBOUND MEMORYSEGMENTREALLOWBOUND + SEGMENTSIZE
; there was a program on the internet [e.g. http://frz.ir/dl/tuts/8086_Assembly.pdf%5D written entirely
; using NASM pseudo-op “db”. For example,
; dw 0xfeeb will generate the same bit patterns as jmp $ in the binary file. The interrupt table and stacksegment and datasegment with pseudo-opcodes db, dw etc. here
; was “jmp-ed” over …
%define TRYIVT ; try out ivt codes … comment this out to exclude ivt codes
%ifdef TRYIVT
; interrupts are a type of messages “muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”
; and the interrupt table [of outgoing becauses/answers/responses {do tha’i … } to incoming messages] is placed as close to the origin nguye^n thu?y 0x0:0x0 as possible with/by the BIOS
; girl immitating the suprememes pointing fingers on our trip to san francisco:
; I know, I know you must follow the sun
;Wherever it leads
;But remember
;If you should fall short of your desires
;Remember life holds for you one guarantee
;You’ll always have me
; And if you should miss my lovin
;One of these old days
;If you should ever miss the arms
;That used to hold you so close, or the lips
;That used to touch you so tenderly
;Just remember what I told you
;The day I set you free
;
;Ain’t no mountain high enough
;Ain’t no valley low enough
;Ain’t no river wild enough
;To keep me from you
; http://youtu.be/VqW2XigtDEU
; universal-loop
; {
; start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // in “gia ba?o”, “ba?o” ~ maintain as in “ba?o thu?/to^`n” …
; try/if ;// tin messages …. the try/if is the “gia” of “gia ba?o” …
; maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // the message “stack” is loaded or push-pop with messages …; // push-and-pop-or-sent-and-receive (&messageNEW-hay-tinLA`NH); // tin and shakespeare’s version of “all roads lead to rome”: “doubt thou the stars are fire doubt truth to be a liar but never doubt I loved ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well'”: 1/19/2014 Sunday Service … Gospel ~ Good News Tin La\nh …”Gia Ba?o”: the “gia” attempts to reach an agreement with the “ba?o” …// salinger on internet news: push/pop/create stack/heap by an expansion assignment (“muo^n loa`i” ; ;catch/else ;// unmaintainable tin/messages or kho’ tin hay kho^ng tin no messages … SBTN Uye^n Thi. commercial for MBR [master boot record] “kho’ tin nhu+ng co’ tha^.t …”
; ; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
; }
; original interrupt vector table in the BIOS
orgbiosivt: times 1024 db 0 ; interrupt vector table: reserve space to push-pop BIOS’ ivt table
orgbiosivtend:
;the original ivtr structure:
orgbiosivtr DW 0 ; For limit storage ; size of ivt structure
DD 0 ; For base storage ; segment:offset address of ivt structure
; interrupt vector table
ivt: times 1024 db 0 ; interrupt vector table: reserve space to push-pop BIOS’ ivt table …
ivtend:
;the ivtr structure:
ivtr DW 0 ; For limit storage ; size of ivt structure
DD 0 ; For base storage ; segment:offset address of ivt structure
; interrup descriptor table
;idt:
;idt_end:
;the idtr structure:
;idtr DW 0 ; For limit storage
; DD 0 ; For base storage
%endif ; TRYIVT
interrupt5count dw 0
interrupt9count dw 0
; data segment
; section .data
;section datasegment align=16 ; start= follows=
;segment datasegment align=16 ; start= follows=
; align 16
;segment .data align=16
;datasegment dw 123
datasegment db ‘Hope Well’
; stack segment
; section .bss
; section stacksegment align=16 ; start= follows=
; segment stacksegment align=16 ; start= follows=
; align 16
;segment .stack align=16
stacksegment resb 64
stacktop:
stacklowerbound equ stacksegment
stackupperbound equ stacktop
stacksize equ $-stacksegment
; from NASM manual
;3.2.4 EQU: Defining Constants
;EQU defines a symbol to a given constant value: when EQU is used, the source line must contain a label. The action of EQU is to define the given label name to the value of its (only) operand. This definition is absolute, and cannot change later. So, for example,
;message db ‘hello, world’
;msglen equ $-message
;defines msglen to be the constant 12. msglen may not then be redefined later. This is not a preprocessor definition either: the value of msglen is evaluated once, using the value of $ (see section 3.5 for an explanation of $) at the point of definition, rather than being evaluated wherever it is referenced and using the value of $ at the point of reference.
;spprevious dw 0
;spnew dw 0
;spcounter times 10 dw 0
; from NASM manual
;message db ‘hello, world’
;msglen equ $-message
;stacktop = stacksegment – datasegment + 64
;segment .text align=16
; set up the data, stack, etc. segment registers
;segment .text align=16
start:
;mov AX, 0x0
;mov AX,seg DATASEGMENT1
;; mov AX, datasegment
;; mov AX, seg datasegment ; error: binary output format does not support segment base references
;; mov AX, [datasegment]
;%ifdef ORIGIN
%if ORIGIN = 0x7c00
mov AX, 0x0
; mov AX, 0x0 + datasegment
; mov AX, PROGRAMSEGMENT
mov DS,AX
; from http://www.supernovah.com/Tutorials/BootSector2.php
; The processor uses the SS:SP segment offset address to determine the location of the stack.
; from http://wiki.osdev.org/Stack:
;Take care when implementing your kernel. If you use segmentation, the DS segment should be configured to have it’s base at the same address as SS does. Otherwise you may run into problems when passing pointers to local variables into functions, because normal GPRs can’t access the stack the way you might think.
;mov AX,seg STACKSEGMENT
;mov AX, 0x0 + stacksegment
mov AX, 0x0
mov SS,AX
;mov SP, 0x0 + stacktop
mov SP, stacktop
;%else
%elif ORIGIN = 0x0
; mov AX, 0x07C0 + datasegment
; mov AX, datasegment
mov AX, 0x07C0
; mov AX, PROGRAMSEGMENT
mov DS,AX
; from http://www.supernovah.com/Tutorials/BootSector2.php
; The processor uses the SS:SP segment offset address to determine the location of the stack.
; from http://wiki.osdev.org/Stack:
;Take care when implementing your kernel. If you use segmentation, the DS segment should be configured to have it’s base at the same address as SS does. Otherwise you may run into problems when passing pointers to local variables into functions, because normal GPRs can’t access the stack the way you might think.
;mov AX,seg STACKSEGMENT
; mov AX, 0x07C0 + stacksegment
;mov AX, stacksegment
mov AX, 0x07C0
mov SS,AX
; mov SP, 0x07C0 + stacktop
mov SP, stacktop
; from http://frz.ir/dl/tuts/8086_Assembly.pdf
;MOV REG, memory
;MOV memory, REG
;MOV REG, REG
;MOV memory, immediate
;MOV 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…
; mov CX, SP
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter], spprevious – spnew
%elif ORIGIN = 0x7990 ; grateful for hexadecimal conversion from http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html and hex calculator from http://www.miniwebtool.com/hex-calculator/?number1=270&operate=1&number2=7990
mov AX, 0x0027
; mov AX, 0x0027 + datasegment
; mov AX, PROGRAMSEGMENT
mov DS,AX
; from http://www.supernovah.com/Tutorials/BootSector2.php
; The processor uses the SS:SP segment offset address to determine the location of the stack.
; from http://wiki.osdev.org/Stack:
;Take care when implementing your kernel. If you use segmentation, the DS segment should be configured to have it’s base at the same address as SS does. Otherwise you may run into problems when passing pointers to local variables into functions, because normal GPRs can’t access the stack the way you might think.
;mov AX,seg STACKSEGMENT
;mov AX, 0x0 + stacksegment
mov AX, 0x0027
mov SS,AX
;mov SP, 0x0027 + stacktop
mov SP, stacktop
%endif ; ORIGIN
;mov AX,seg STACKSEGMENT
; mov AX, stacksegment
; mov SS,AX
; mov SP,stacktop
; to use the stack, use “call” and “ret” instead of “jmp”
; effectively, the illegal “mov eip, label” ~ legal “jmp label”
; or just let the program flows, without the jmp, to instructions that follow
; jmp main ; jmp Loads EIP with the specified address
; PUSH instruction from programmer’s reference manual
;IF StackAddrSize = 16
;THEN
; IF OperandSize = 16 THEN
; SP := SP – 2;
; (SS:SP) := (SOURCE); (* word assignment *)
; ELSE
; SP := SP – 4;
; (SS:SP) := (SOURCE); (* dword assignment *)
; FI;
;ELSE (* StackAddrSize = 32 *)
; IF OperandSize = 16
; THEN
; ESP := ESP – 2;
; (SS:ESP) := (SOURCE); (* word assignment *)
; ELSE
; ESP := ESP – 4;
; (SS:ESP) := (SOURCE); (* dword assignment *)
; FI;
;FI;
; RET instruction
;IF instruction = near RET
;THEN;
; IF OperandSize = 16
; THEN
; IP := Pop();
; EIP := EIP AND 0000FFFFH;
; ELSE (* OperandSize = 32 *)
; EIP := Pop();
; FI;
; IF instruction has immediate operand THEN eSP := eSP + imm16; FI;
;FI
; CALL instruction
;IF rel16 or rel32 type of call
;THEN (* near relative call *)
; IF OperandSize = 16
; THEN
; Push(IP);
; EIP := (EIP + rel16) AND 0000FFFFH;
; ELSE (* OperandSize = 32 *)
; Push(EIP);
; EIP := EIP + rel32;
; FI;
;FI;
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; mov [spprevious], SP
; call word main ; call = push + jmp; ret = pop + jmp
call word main ; call = push + jmp; ret = pop + jmp
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; from http://wiki.osdev.org/Babystep2:
; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
; of segment and offset that point to the same address.
%define REALADDRESS(SEGMENTNO,OFFSETNO) SEGMENTNO*16+OFFSETNO
%define VERIFYSEGMENTADDRESSBOUND(SEGMENTADDRESSTOVERIFY, OFFSETADDRESSTOVERIFY) \
(REALADDRESS(SEGMENTADDRESSTOVERIFY,OFFSETADDRESSTOVERIFY) > MEMORYSEGMENTREALLOWBOUND) \
& (REALADDRESS(SEGMENTADDRESSTOVERIFY,OFFSETADDRESSTOVERIFY) < MEMORYSEGMENTREALUPPERBOUND)
; generate some virtual segment:offset address for use with a real address …
; TO DO: align the generated addresses to “natural” byte boundaries …
; %define GENERATESEGMENTADDRESS(REALADDRESSNO, &GENSEGMENTNO, &GENOFFSETNO) …………….
; %define GENERATEVIRTUALSEGMENTADDRESS(REALADDRESSNO, VIRTUALOFFSETADDRESSINPUT) (REALADDRESSNO – VIRTUALOFFSETADDRESSINPUT)/16
; %define GENERATEOFFSETNO(REALADDRESSNO, VIRTUALSEGMENTADDRESSINPUT) (REALADDRESSNO – VIRTUALSEGMENTADDRESSINPUT * 16)
; from http://geezer.osdevbrasil.net/johnfine/segments.htm:
;The way it really works
; Each segment register is really four registers: A selector register
;A base register
;A limit register
;An attribute register
;
;In all modes, every access to memory that uses a segment register uses the base, limit, and attribute portions of the segment register and does not use the selector portion.
;Every direct access to a segment register (PUSHing it on the stack, MOVing it to a general register etc.) uses only the selector portion. The base, limit, and attribute portions are either very hard or impossible to read (depending on CPU type). They are often called the “hidden” part of the segment register because they are so hard to read.
;Intel documentation refers to the hidden part of the segment register as a “descriptor cache”. This name obscures the actual behavior of the “hidden” part.
; In real mode (or V86 mode), when you write any 16-bit value to a segment register, the value you write goes into the selector and 16 times that value goes into the base. The limit and attribute are not changed.
;In pmode, any write to a segment register causes a descriptor to be fetched from the GDT or LDT and unpacked into the base, limit and attribute portion of the segment register. (Special exception for the NULL Selector).
;When the CPU switchs between real mode and pmode, the segment registers do not automatically change. The selectors still contain the exact bit pattern that was loaded into them in the previous mode. The hidden parts still contain the values they contained before, so the segment registers can still be used to access whatever segments they refered to before the switch.
;Writes to a segment register
;When I refer to “writing to a segment register”, I mean any action that puts a 16-bit value into a segment register.
;The obvious example is something like:
; MOV DS,AX
;However the same rules apply to many other situations, including: POP to a segment register.
;FAR JMP or CALL puts a value in CS.
;IRET or FAR RET puts a value in CS.
;Both hardware and software interrupts put a value in CS.
;A ring transition puts a value in both SS and CS.
;A task switch loads all the segment registers from a TSS.
; from the Programmer’s Reference Manual
;The segment containing the currently executing sequence of instructions is known as the current code segment;
;it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using
;as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment
;control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.
main:
; to use the stack, use “call” and “ret” instead of “jmp”
;jmp screensetup ; or just let the program flows, without the jmp, to instructions that follow
; call screensetup
call word screensetup
; call clearscreenpixels
call word clearscreenpixels
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; mov [spprevious], SP
%define SAYHELLO 1
%ifdef SAYHELLO
; call sayhello
call word sayhello
%endif ; SAYHELLO
; mov [spnew], SP
; mov word [spcounter + 2 * 1], spprevious – spnew
%ifdef TRYIVT
call changeivt.loadorgbiosivtwithbiosivt
call changeivt.loadivtwithbiosivt
;call changeivt.loadivtwithorgbiosivt
;Setting:
;mov ax, [intnum*4] ; offset
;mov ax [intnum*4+2] ; segment
; pbs “peg and cat” …. suggestively similar “peg and cat” bedding at baby r us 3/13/2014
; substitute custom interrupt numbers 5 and 9 into new ivt table created by cloning from original BIOS ivt table: neighbor dude with custom truck 3/13/2014
call changeivt.insertcustominterruptsintoivt
call changeivt.setivt
; test custom interrupt numbers 5 and 9 … here …
int 5 ; manual interrupt
int 9 ; manual interrupt
; test safe stack calls SAFECALLS’s with int 5 here ………
; ………
; test int 9 here ………………..
; automatic interrupt: keyboard presses will create int 9 …
; test: however ctr-alt-del will have no effect on custom interrupt int 9 …
;xor cx, cx
waitforinterrupts: cmp word [interrupt9count], 10 ; key press wait loop …
jne waitforinterrupts
;loopne waitforinterrupts
; xor cx, cx
;WaitforData: in al, 64h ;Read kbd status port.
; test al, 10b ;Data in buffer?
; loopz WaitforData ;Wait until data available.
; restore original interrupt vector table from BIOS with original interrupt numbers 5 and 9
; call changeivt.loadivtwithorgbiosivt
call changeivt.loadbiosivtwithorgbiosivt
call changeivt.setorgivt
; ctr-alt-del should have an effect again here ………….
jmp seeyoulater
%endif ; TRYIVT
%ifdef TRYIVTORIG
; cli ; disable interrupts during change of interrupt vector table
;; call changeivt.loadorgbiosivtwithbiosivt
;call changeivt.loadivtwithbiosivt
;; call changeivt.loadivtwithorgbiosivt
;Setting:
;mov ax, [intnum*4] ; offset
;mov ax [intnum*4+2] ; segment
; pbs “peg and cat” …. suggestively similar “peg and cat” bedding at baby r us 3/13/2014
; substitute custom interrupt numbers 5 and 9 into new ivt table created by cloning from original BIOS ivt table: neighbor dude with custom truck 3/13/2014
; address of BIOS interrupts routines
interrupt5segment dw 0
interrupt5offset dw 0
interrupt9segment dw 0
interrupt9offset dw 0
mov ax, 0x0
mov gs, ax
mov ax, [gs:5*4] ; [0x0:5*4]
mov [interrupt5offset], ax
mov ax, [gs:5*4+2] ; [0x0:5*4+2]
mov [interrupt5segment], ax
mov ax, [gs:9*4] ; [0x0:9*4]
mov [interrupt5offset], ax
mov ax, [gs:9*4+2] ; [0x0:9*4+2]
mov [interrupt5segment], ax
; mov dword [interrupt5serviceroutine], [0x0:5*4]
; mov dword [interrupt9serviceroutine], [0x0:9*4]
cli ; pause interrupts
mov AX, safeinterrupt5sr ; offset
; mov dword [ivt + 5*4], AX
mov [gs:5*4], AX
mov AX, PROGRAMSEGMENT ; segment
; mov dword [ivt + 5*4+2], AX
mov [gs:5*4+2], AX
mov AX, safeinterrupt9sr ; offset
; mov dword [ivt + 9*4], AX
mov [gs:9*4], AX
mov AX, PROGRAMSEGMENT ; segment
; mov dword [ivt + 9*4+2], AX
mov [gs:9*4+2], AX
sti ; re-enable interrupts
;call changeivt.loadbiosivtwithivt
;; call changeivt.setivt ; inform processor where new ivt table is …
;sti ; re-enable interrupts
; test custom interrupt numbers 5 and 9 … here …
int 5
int 9
; restore original interrupt vector table from BIOS with original interrupt numbers 5 and 9
; call changeivt.loadivtwithorgbiosivt
;; call changeivt.loadbiosivtwithorgbiosivt
;; call changeivt.setorgivt
cli ; pause interrupts
mov ax, [interrupt5offset]
mov [gs:5*4], ax
mov ax, [interrupt5segment]
mov [gs:5*4+2], ax
mov ax, [interrupt9offset]
mov [gs:9*4], ax
mov ax, [interrupt9segment]
mov [gs:9*4+2], ax
sti ; re-enable interrupts
;sti ; re-enable interrupts
%endif ; TRYIVTORIG
;%define TRYIVT 1 ; non-zero
%ifdef TRYIVT
; from Programmer’s Reference Manual
;IF PE = 0
;THEN GOTO REAL-ADDRESS-MODE;
;ELSE GOTO PROTECTED-MODE;
;FI;
;REAL-ADDRESS-MODE:
; Push (FLAGS);
; IF = 0; (* Clear interrupt flag *)
; TF = 0; (* Clear trap flag *)
; Push(CS);
; Push(IP);
; (* No error codes are pushed *)
; CS := IDT[Interrupt number * 4].selector;
; IP := IDT[Interrupt number * 4].offset;
;interrrupts are a type of (messageA + messageB + messageC + messageD + tinLa`nh + …):
; from http://wiki.osdev.org/Interrupt_Vector_Table
; The IVT is typically located at 0000:0000H, and is 400H bytes in size (4 bytes for each interrupt). Although the default address can be changed using the LIDT instruction on newer CPUs, this is usually not done because it is both inconvenient and incompatible with other implementations and/or older software (e.g. MS-DOS programs). However, note that the code must remain in the first MiB of RAM.
; format of the ivt table entries [1024/4=256 entries] is
; +———–+———–+
; | Segment | Offset |
; +———–+———–+
; 4 2 0
; from https://www.uop.edu.jo/issa/Assembly/programming.pdf
;ivt table is 1k in real mode, 2k in protected mode
;ivt entry is 4 bytes in real mode, 8 bytes in protected mode
;size of the pointer to ivt table is 4 bytes for addresses from 00000000 to 000003FF, is 8 bytes in protected mode
;%define BIVTSTART 0x0; Start of BIOS ivt data area
;struc tBIOSIVT ; its structure
; .SEGMENT RESW 1
; .OFFSET RESW 1
;endstruc
; the ivt table defined in the data segment “datasegment” above
;;.ivt: times 1024 db 0 ; interrupt vector table: reserve space to push-pop BIOS’ ivt table
;;.ivtend:
;;fourcxvar dw 0
;; mov ax, 0x0
;; mov gs, ax
;; mov ax, [gs:5*4] ; [0x0:5*4]
;; mov [interrupt5offset], ax
;; mov ax, [gs:5*4+2] ; [0x0:5*4+2]
;; mov [interrupt5segment], ax
; from NASM manual:
;3.3 Effective Addresses
;An effective address is any operand to an instruction which references memory. Effective addresses, in NASM, have a very simple syntax: they consist of an expression evaluating to the desired address, enclosed in square brackets. For example:
;wordvar dw 123
; mov ax,[wordvar]
; mov ax,[wordvar+1]
; mov ax,[es:wordvar+bx] ; this is gives no error
; however:
; mov ax,[es:wordvar+cx] ; this gives “invalid effective address” error
; mov ax,[es:wordvar+2*bx] ; this gives “invalid effective address” error
; mov ax,[es:wordvar+10*bx] ; this gives “invalid effective address” error
; mov ax,[es:wordvar+4*bx] ; this gives “invalid effective address” error
; mov eax,[es:wordvar+4*ebx] ; this gives no error
; mov eax,[es:wordvar+10*ebx] ; this gives “invalid effective address” error
; also segment registers:
; mov gs, 0x0 ; “immediate” gives error
; mov gs, [worvar] ; “memory” is all right
; mov gs, ax ; “register” is all right
; from http://www.supernovah.com/Tutorials/Assembly3.php:
;16-bit Real Mode Addressing
;Non Memory Addressing Modes
;The non memory addressing modes in 16 bits are the same as 32-bit non memory addressing modes except that you can only use 16-bit registers or smaller. Also the largest displacement in 16-bit addresses can be at most 16 bits.
;Memory Addressing Modes
;In 16-bit real mode we can address memory using 16-bit or 8-bit registers. The addressing modes in 16 bits are much more restrictive than in 32 bits. The table below lists the components that can make up a 16-bit address.
;Displacement Base Index Scale
;no disp BX SI None
;8-bit disp BP DI
;16-bit disp
;32-bit Protected Mode Addressing
;Non Memory Addressing Modes
;These addressing modes do not access memory. These modes will work with either static data or registers.
;Memory Addressing Modes
;These addressing modes perform memory operations such as reading from and writing to memory. Because of the memory access, it is often slower than using the non memory addressing modes. Of course a program could not rely on immediate and register addressing modes alone, therefore the processor allows you to access memory in many different ways. Most instructions will only allow one operand to use a memory addressing mode while the other operand must use either the immediate or register addressing mode.
;Memory addresses are composed of several different components. The table below lists the components that can make up a memory address.
;Displacement Base Index Scale
;no disp EAX EAX 1
;16-bit disp EBX EBX 2
;32-bit disp ECX ECX 4
; EDX EDX 8
; ESI ESI
; EDI EDI
; EBP EBP
; ESP
; from Programmer’s Reference Manual:
;Figure 2-10. Effective Address Computation
; SEGMENT + BASE + (INDEX * SCALE) + DISPLACEMENT
;
; + +
; | — | + + + +
; + + | EAX | | EAX | | 1 |
; | CS | | ECX | | ECX | | | + +
; | SS | | EDX | | EDX | | 2 | | NO DISPLACEMENT |
; -| DS |- + -| EBX |- + -| EBX |- * -| |- + -| 8-BIT DISPLACEMENT |-
; | ES | | ESP | | — | | 4 | | 32-BIT DISPLACEMENT |
; | FS | | EBP | | EBP | | | + +
; | GS | | ESI | | ESI | | 6 |
; + + | EDI | | EDI | + +
; + + + +
changeivt:
.loadorgbiosivtwithbiosivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; setup loop counter
mov cx, 512 ; //1024 = 512 * sizeof(word) … setup loop counter
; loop instruction involves cx but 16 bit effective address requires bx …
.looploadorgbiosivtwithbiosivt:
mov word ax, [gs:bx] ; 16 bit effective address requires loop counter to use bx or bp instead of cx etc.
mov word [orgbiosivt + bx], ax
;mov dword [orgbiosivt + cx*4], [es:4*di]
sub bx, 2
loop .looploadorgbiosivtwithbiosivt
mov ax, [gs:0000]
mov [orgbiosivt + 0], ax ; since “loop” exists when CX is 0, 0th entry must be done manually
jmp .exitchangeivt
.loadbiosivtwithorgbiosivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; setup loop counter
mov cx, 512 ; //1024 = 512 * sizeof(word) … setup loop counter
.looploadbiosivtwithorigbiosivt:
mov word ax, [orgbiosivt + bx]
mov word [gs:bx], ax
sub bx, 2
loop .looploadbiosivtwithorigbiosivt
mov word ax, [orgbiosivt + 0] ; since “loop” exists when CX is 0, 0th entry must be done manually
mov word [gs:0], ax
jmp .exitchangeivt
.loadivtwithorgbiosivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; //1024 = 512 * sizeof(word) … setup loop counter
mov cx, 512 ; setup loop counter
.looploadivtwithorgbiosivt:
mov word ax, [orgbiosivt + bx]
mov word [ivt + bx], ax
sub bx, 2
loop .looploadivtwithorgbiosivt
mov word ax, [orgbiosivt + 0] ; since “loop” exists when CX is 0, 0th entry must be done manually
mov word [ivt + 0], ax
jmp .exitchangeivt
.loadivtwithbiosivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; //1024 = 512 * sizeof(word) … setup loop counter
mov cx, 512 ; setup loop counter
.looploadivtwithbiosivt:
mov word ax, [gs:bx] ; 16 bit effective address requires loop counter to use bx or bp instead of cx etc.
mov word [ivt + bx], ax
sub bx, 2
loop .looploadivtwithbiosivt
mov word ax, [gs:0] ; since “loop” exists when CX is 0, 0th entry must be done manually
mov word [ivt + 0], ax
jmp .exitchangeivt
.loadbiosivtwithivt:
xor ax, ax ; segment of original BIOS IVT table is 0x0
mov gs, ax ; segment of original BIOS IVT table is 0x0
mov bx, 1024 ; //1024 = 512 * sizeof(word) … setup loop counter
mov cx, 512 ; setup loop counter
.looploadbiosivtwithivt:
mov word ax, [ivt + bx]
mov word [gs:bx], ax
sub bx, 2
loop .looploadbiosivtwithivt
mov word ax, [ivt + 0] ; since “loop” exists when CX is 0, 0th entry must be done manually
mov word [gs:0], ax
jmp .exitchangeivt
.exitchangeivt:
ret
; from http://wiki.osdev.org/GDT_Tutorial
;gdtr DW 0 ; For limit storage
; DD 0 ; For base storage
;GDT:
;GDT_end:
;setGdt:
; xor EAX, EAX ; zero EAX register for use as scratch
; mov AX, DS ; the data segment “datasegment”
; shl EAX, 4 ; The linear address should here be computed as segment * 16 + offset. shift left 4 ~ multiply by 16
; add EAX, ”GDT” ; add offset to GDT structure in segment “datasegment”
; mov [gdtr + 2], eax ; initialize gdtr’s base storage to segment:offset address of GDT structure
; mov EAX, ”GDT_end”
; sub EAX, ”GDT” ; size of GDT structure = GDT end – GDT begin
; mov [gdtr], AX ; initialize gdtr’s to size of GDT structure = GDT end – GDT begin
; lgdt [gdtr] ; set the gdt with lgdt
; ret
; the idt or ivt table defined in the data segment “datasegment” above
;;.ivt: times 1024 db 0 ; interrupt vector table: reserve space to push-pop BIOS’ ivt table
;;.ivtend:
;;ivtend:
;; interrup descriptor table
;idt:
;idt_end:
;the idtr or ivtr structures defined in the data segment “datasegment” above:
;idtr DW 0 ; For limit storage
; DD 0 ; For base storage
;ivtr DW 0 ; For limit storage
; DD 0 ; For base storage
;.setidt: ; set the interrupt descriptor table IDT
.setivt: ; set the interrupt vector table IVT
xor EAX, EAX ; zero EAX register for use as scratch
mov AX, DS ; the data segment “datasegment”
shl EAX, 4 ; The linear address should here be computed as segment * 16 + offset. shift left 4 ~ multiply by 16
; add EAX, idt ; add offset to IDT structure in segment “datasegment”
add EAX, ivt ; add offset to IVT structure in segment “datasegment”
; mov [idtr + 2], eax ; initialize gdtr’s base storage to segment:offset address of IDT structure
mov [ivtr + 2], eax ; initialize ivtr’s base storage to segment:offset address of IVT structure
; mov EAX, idt_end
mov EAX, ivtend
; sub EAX, idt ; size of GDT structure = IDT end – IDT begin
sub EAX, ivt ; size of IDT structure = IVT end – IVT begin
; mov [idtr], AX ; initialize gdtr’s to size of IDT structure = IDT end – IDT begin
mov [ivtr], AX ; initialize ivtr’s to size of IVT structure = IVT end – IVT begin
; lgdt [idtr] ; set the idt with lgdt
;lgdt [ivtr] ; set the ivt with lgdt
lidt [ivtr] ; set the ivt with lgdt
; from Programmer’s Reference Manual
; IF instruction = LIDT
;THEN
; IF OperandSize = 16
; THEN IDTR.Limit:Base := m16:24 (* 24 bits of base loaded *)
; ELSE IDTR.Limit:Base := m16:32
; FI;
;ELSE (* instruction = LGDT *)
; IF OperandSize = 16
; THEN GDTR.Limit:Base := m16:24 (* 24 bits of base loaded *)
; ELSE GDTR.Limit:Base := m16:32;
; FI;
;FI;
;.exit:
;ret
jmp .exitchangeivt
.setorgivt: ; set the interrupt vector table IVT
xor EAX, EAX ; zero EAX register for use as scratch
; mov AX, DS ; the data segment “datasegment”
mov AX, 0x0 ; the data segment “datasegment”
shl EAX, 4 ; The linear address should here be computed as segment * 16 + offset. shift left 4 ~ multiply by 16
; add EAX, idt ; add offset to IDT structure in segment “datasegment”
; add EAX, ivt ; add offset to IVT structure in segment “datasegment”
add EAX, 0x0 ; add offset to IVT structure in segment “datasegment”
; mov [idtr + 2], eax ; initialize gdtr’s base storage to segment:offset address of IDT structure
mov [orgbiosivtr + 2], eax ; initialize ivtr’s base storage to segment:offset address of IVT structure
; mov EAX, idt_end
mov EAX, orgbiosivtend
; sub EAX, idt ; size of GDT structure = IDT end – IDT begin
sub EAX, orgbiosivt ; size of IVT structure = IVT end – IVT begin
mov AX, 400h ; initialize size of ivtr to … size of original BIOS IVT structure
; mov [idtr], AX ; initialize gdtr’s to size of IDT structure = IDT end – IDT begin
mov [orgbiosivtr], AX ; initialize ivtr’s to size of IVT structure = IVT end – IVT begin
; lgdt [idtr] ; set the idt with lgdt
;lgdt [orgbiosivtr] ; set the ivt with lgdt
lidt [orgbiosivtr] ; set the ivt with lgdt
; from Programmer’s Reference Manual
; IF instruction = LIDT
;THEN
; IF OperandSize = 16
; THEN IDTR.Limit:Base := m16:24 (* 24 bits of base loaded *)
; ELSE IDTR.Limit:Base := m16:32
; FI;
;ELSE (* instruction = LGDT *)
; IF OperandSize = 16
; THEN GDTR.Limit:Base := m16:24 (* 24 bits of base loaded *)
; ELSE GDTR.Limit:Base := m16:32;
; FI;
;FI;
;.exit:
;ret
jmp .exitchangeivt
; pbs “peg and cat” …. suggestively similar “peg and cat” bedding at baby r us 3/13/2014
; substitute custom interrupt numbers 5 and 9 into new ivt table created by cloning from original BIOS ivt table: neighbor dude with custom truck 3/13/2014
.insertcustominterruptsintoivt:
cli ; pause interrupts
mov AX, safeinterrupt5sr ; offset
; mov dword [ivt + 5*4], AX
;; mov [gs:5*4], AX ; insert offset part of address of custom interrupt service routine into BIOS ivt
mov [ivt + 5*4], AX ; insert offset part of address of custom interrupt service routine into ivt
mov AX, PROGRAMSEGMENT ; segment
; mov dword [ivt + 5*4+2], AX
;; mov [gs:5*4+2], AX ; insert segment part of address of custom interrup service routine into BIOS ivt
mov [ivt + 5*4+2], AX ; insert segment part of address of custom interrup service routine into ivt
mov AX, safeinterrupt9sr ; offset
; mov dword [ivt + 9*4], AX
;; mov [gs:9*4], AX ; insert offset part of address of custom interrupt service routine into BIOS ivt
mov [ivt + 9*4], AX ; insert offset part of address of custom interrupt service routine into ivt
mov AX, PROGRAMSEGMENT ; segment
; mov dword [ivt + 9*4+2], AX
;; mov [gs:9*4+2], AX ; insert segment part of address of custom interrupt service routine into BIOS ivt
mov [ivt + 9*4+2], AX ; insert segment part of address of custom interrupt service routine into ivt
sti ; re-enable interrupts
jmp .exitchangeivt
;;.removecustominterruptsfromivt
; restore original interrupt vector table from BIOS with original interrupt numbers 5 and 9
; call changeivt.loadivtwithorgbiosivt
;; call changeivt.loadbiosivtwithorgbiosivt
;; call changeivt.setorgivt
;; cli ; pause interrupts
;; mov ax, [interrupt5offset]
;; mov [gs:5*4], ax
;; mov ax, [interrupt5segment]
;; mov [gs:5*4+2], ax
;; mov ax, [interrupt9offset]
;; mov [gs:9*4], ax
;; mov ax, [interrupt9segment]
;; mov [gs:9*4+2], ax
;; sti ; re-enable interrupts
;sti ; re-enable interrupts
;; jmp .exitchangeivt
%endif ; TRYIVT
; gia ba?o suggested for balance to “say hello”:
seeyoulater:
; call exit
call word exit
; call hang
call word hang
ret ; return
; from http://www.supernovah.com/Tutorials/BootSector4.php:
;Video Memory
;As previously stated, what is printed to the screen is simply controlled by a special section of memory called
;the video memory (or VGA memory). This section of memory is then periodically copied to the video device
;memory which is then presented to the screen by the Digital Analog Converter (DAC). Currently we are in text
;mode 03h which is a form of EGA. The video memory for text mode 3h begins at 0xB8000. Text mode 03h is 80 characters wide
;and 25 characters tall. This gives us 2000 total characters (80 * 25). Each character consists of 2 bytes which
;yields 4000 bytes of memory in total. So this means that text mode 03h stores it’s video information (the information that is
;printed to the screen) at the memory address 0xB8000 and it takes up 4000 bytes of memory.
;Printing Character to the Screen
;The first we must do in order to print character to the screen is to get a segment register setup that points
;to the memory location 0xB8000 [= 753664 = 47104 * 16]. Remember that segments in real mode have the lower four bits implicitly
;set to zero and because each hex digit represents four bits we can easily drop the right most zero on the
;memory address when storing it in a segment register. We will use the ES segment register because we
;still want to access our data with the DS segment so we don’t run into problems when using instructions that
;implicitly use the DS segment by default.
;mov AX,0xB800 ;// = 47104
;mov ES,AX
;screen output …
;for the screen, the messages in (“muo^n loa`i” ;(“muo^n loa`i va` pixel1 va` pixel2 va` … ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”)
screensetup: ; point ES to video memory
.setupvideosegment:
mov AX,0xB800 ;// = 47104
mov ES,AX
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
;jmp clearscreenpixels
ret ; return
; from http://staff.ustc.edu.cn/~xyfeng/research/cos/resources/machine/mem.htm:
;0x0000:0x0000 1024 bytes Interrupt Vector Table
;0x0040:0x0000 256 bytes BIOS Data Area
;0x0050:0x0000 ? Free memory
;0x07C0:0x0000 512 bytes Boot sector code
;0x07E0:0x0000 ? Free memory
;0xA000:0x0000 64 Kb Graphics Video Memory
;0xB000:0x0000 32 Kb Monochrome Text Video Memory
;0xB800:0x0000 32 Kb Color Text Video Memory
;0xC000:0x0000 256 Kb1 ROM Code Memory
;0xFFFF:0x0000 16 bytes More BIOS data
;Clearing the Background
;Clearing the background is rather trivial. The goal is to set all of the attribute bytes to the background color
;you wish to clear it to. The basic idea is to create a loop that will set every other byte, starting at the first
;attribute byte, to the background color we wish to clear to. We must also be sure to only clear all of the attributes that
;are used to represent the string. In other words, be sure not to go past the last attribute byte. The last attribute byte is
;found at 80 * 25 * 2 – 1. The 80 is the width and the 25 is the height. The 2 is there because two bytes make up each
;character; one for the character and one for the attribute. Finally the 1 is subtracted because our first attribute byte is
;actually the second byte at the beginning The 1 simply takes into account that we start our count at one instead of zero.
;The right most hex digit sets the lower four bits of the attribute byte. The lower four bits control the character color while the upper
;four bits (the left most hex digit) control the background color and flash bit. We set the background and flash bits (upper four bits) to 0h
; because 0h corresponds to the color black with no flashing.
;color index hex 64-color palette index
;Black 0 00h 0
;Blue 1 01h 1
;Green 2 02h 2
;Cyan 3 03h 3
;Red 4 04h 4
;Magenta 5 05h 5
;Brown 6 06h 20
;Light Gray 7 07h 7
;Dark Gray 8 08h 56
;Bright Blue 9 09h 57
;Bright Green 10 0Ah 58
;Bright Cyan 11 0Bh 59
;Bright Red 12 0Ch 60
;Bright Magenta 13 0Dh 61
;Bright Yellow 14 0Eh 62
;Bright White 15 0Fh 63
; from http://gd.tuwien.ac.at/languages/c/programming-bbrown/advcw2.htm and
;offset = (( row * 0x50 + column ) * 2 ) + ( pagenum * 0x1000 )
clearscreenpixels:
mov CX,0x50 * 25 * 2 – 1
mov BX,1
.Loopthroughscreenpixels:
cmp BX,CX
ja .finishclearscreenpixels ;CF = 0 and ZF = 0
;ja Loads EIP with the specified address, if first operand of previous CMP instruction is greater than the second. ja is the same as jg, except that it performs an unsigned comparison.
mov byte [ES:BX],70h ;Set background to light gray
;and the text to black
;with no flashing text
add BX,2
jmp .Loopthroughscreenpixels ; jmp Loads EIP with the specified address
.finishclearscreenpixels:
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
;jmp exit
;jmp sayhello
ret
%ifdef SAYHELLO
sayhello:
mov byte [ES:0],’h’
mov byte [ES:2],’o’
mov byte [ES:4],’p’
mov byte [ES:6],’e’
mov byte [ES:8],’ ‘
mov byte [ES:10],’w’
mov byte [ES:12],’e’
mov byte [ES:14],’l’
mov byte [ES:16],’l’
; from NASM manual
; wordvar dw 123
; mov ax,[wordvar]
; mov ax,[wordvar+1]
; mov ax,[es:wordvar+bx]
; test stacksegment ; stack ~ buffer … to^nan does not have enough fat/buffer on him
; xor bl, bl
; from http://www.supernovah.com/Tutorials/Assembly4.php:
;When the processor pushes data onto the stack it does the following operations:
;1.Subtract 4 from SP or ESP
;2.Move the source data to the memory location [SS:SP] or [SS:ESP]
; push dword 117 ;Push the value 117 as a dword onto the stack
; push dword [0x500] ;Push the value at the memory location 0x500 onto the stack
; push byte ‘H’ ;Push the value 117 as a dword onto the stack ; nasm gives no error with the “byte” specification, see http://f.osdev.org/viewtopic.php?f=1&t=13399
; push byte ‘o’ ;Push the value 117 as a dword onto the stack
; push byte ‘p’ ;Push the value 117 as a dword onto the stack
; push byte ‘e’ ;Push the value 117 as a dword onto the stack
; push byte ‘W’ ;Push the value 117 as a dword onto the stack
; push byte ‘e’ ;Push the value 117 as a dword onto the stack
; push byte ‘l’ ;Push the value 117 as a dword onto the stack
; from http://www.supernovah.com/Tutorials/BootSector4.php:
; When the processor pushes data onto the stack it does the following operations:
;1.Subtract 4 from SP or ESP
;2.Move the source data to the memory location [SS:SP] or [SS:ESP]
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; mov [spprevious], SP
push ‘H ‘ ;Push the value 117 as a dword onto the stack
;pushd ‘H ‘ ;Push the value 117 as a dword onto the stack
;pushw ‘H ‘ ;Push the value 117 as a dword onto the stack
;push word ‘H ‘ ;Push the value 117 as a dword onto the stack
;push dword ‘H ‘ ;Push the value 117 as a dword onto the stack
; mov [spnew], SP
; mov word [spcounter + 2 * 2], spprevious – spnew
push ‘O ‘ ;Push the value 117 as a dword onto the stack
push ‘P ‘ ;Push the value 117 as a dword onto the stack
push ‘E ‘ ;Push the value 117 as a dword onto the stack
push ‘W ‘ ;Push the value 117 as a dword onto the stack
push ‘E ‘ ;Push the value 117 as a dword onto the stack
push ‘L ‘ ;Push the value 117 as a dword onto the stack
;stacktop = stacksegment – datasegment + 64
; xor bl, bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 0] ; ‘l’
; mov byte [ES:30], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 1] ; ‘e’
; mov byte [ES:32], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 2] ; ‘W’
; mov byte [ES:34], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 3] ; ‘e’
; mov byte [ES:36], bl
xor bl, bl
; STACK states at various points …
; *****************
; *****************
; *****************
; *****************
; ***************** << SP
; ***************** 2 bytes after call main
; *****************
; *****************
; *****************
; ***************** << SP
; ***************** + 2 bytes after call sayhello
; *****************
; ***************** 2 bytes after call main
; *****************
; ***************** << SP
; ***************** + 2 bytes after PUSH ‘H ‘
; *****************
; ***************** + 2 bytes after call sayhello
; *****************
; ***************** 2 bytes after call main
; *****************
; mov byte bl, [stacktop – 4 * 2 + 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte bl, [stacktop – 2 – 2 – 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:60], bl ; ‘H ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:62], bl ; ‘O ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:64], bl ; ‘P ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:66], bl ; ‘E ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:68], bl ; ‘W ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:70], bl ; ‘E ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:72], bl ; ‘L ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:74], bl
; from http://stackoverflow.com/questions/15792702/convert-byte-to-string-in-x86-assembly-language
;.data
;mystr db 33 dup(0)
;
;.code
;
;EaxToBinaryString:
; mov ebx, offset mystr
; mov ecx, 32
;EaxToBinaryString1:
; mov dl, ‘0’ ; replace ‘0’ with 0 if you don’t want an ASCII string
; rol eax, 1
; adc dl, 0
; mov byte ptr [ebx], dl
; inc ebx
; loop EaxToBinaryString1
; ret
; from http://stackoverflow.com/questions/1922134/printing-out-a-number-in-assembly-language
; mov al,4
; or al,30h ;Important! =>Convert Character to Number!
; mov i,al
;
; MOV AH, 2 ;
; MOV DL, i ; Print Character.
; INT 21H ;
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; xor bl, bl
; mov byte bl, [spcounter + 2 * 0]
; mov byte [ES:76], bl
; mov byte bl, [spcounter + 2 * 1]
; mov byte [ES:7], bl
; mov byte bl, [spcounter + 2 * 2]
; mov byte [ES:], bl
xor bl, bl
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘L ‘
;mov byte bl, [stacktop – 0]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
mov byte [ES:56], bl
;mov byte bl, [stacktop – 4]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘E ‘
mov byte [ES:54], bl
;mov byte bl, [stacktop – 8]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘W ‘
mov byte [ES:52], bl
;mov byte bl, [stacktop – 12]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘E ‘
mov byte [ES:46], bl
;mov byte bl, [stacktop – 16]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘P ‘
mov byte [ES:44], bl
;mov byte bl, [stacktop – 20]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘O ‘
mov byte [ES:42], bl
;mov byte bl, [stacktop – 24]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘H ‘
mov byte [ES:40], bl
; test datasegment
xor bl, bl
mov byte bl, [datasegment]
; mov byte bl, [0]
; mov byte bl, [DS:0]
mov byte [ES:20], bl
mov byte bl, [datasegment + 1]
; mov byte bl, [1]
mov byte [ES:22], bl
mov byte bl, [datasegment + 2]
; mov byte bl, [2]
mov byte [ES:24], bl
mov byte bl, [datasegment + 3]
; mov byte bl, [3]
mov byte [ES:26], bl
mov byte bl, [datasegment + 4]
; mov byte bl, [4]
mov byte [ES:28], bl
mov byte bl, [datasegment + 5]
; mov byte bl, [5]
mov byte [ES:30], bl
mov byte bl, [datasegment + 6]
; mov byte bl, [6]
mov byte [ES:32], bl
mov byte bl, [datasegment + 7]
; mov byte bl, [7]
mov byte [ES:34], bl
; mov byte [ES:16], [datasegment + 1]
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
;jmp exit
ret ; sayhello
; test interrupt-support stack boundaries
; from http://www.eecg.toronto.edu/~amza/www.mindsec.com/files/x86regs.html
;SS:EBP EBP BP : Stack Base pointer register
; Holds the base address of the [current] stack [frame]
;SS:ESP ESP SP : Stack pointer register
; Holds the top address of the stack
; from NASM manual:
;4.3 Multi-Line Macros: %macro
;Multi-line macros are much more like the type of macro seen in MASM and TASM: a multi-line macro definition in NASM looks something like this.
;%macro prologue 1
; push ebp
; mov ebp,esp
; sub esp,%1
;%endmacro
; from Programmer’s Reference Manual:
;1.The stack pointer (ESP) register. ESP points to the top of the push-down stack (TOS). It is referenced implicitly by PUSH and POP operations, subroutine calls and returns, and interrupt operations. When an item is pushed onto the stack (see Figure 2-7 ), the processor decrements ESP, then writes the item at the new TOS. When an item is popped off the stack, the processor copies it from TOS, then increments ESP. In other words, the stack grows down in memory toward lesser addresses.
; BOUND instruction:
;62 /r BOUND r16,m16&16 10 Check if r16 is within bounds
; (passes test)
;62 /r BOUND r32,m32&32 10 Check if r32 is within bounds
; (passes test)
;IF (LeftSRC < [RightSRC] OR LeftSRC > [RightSRC + OperandSize/8])
; (* Under lower bound or over upper bound *)
;THEN Interrupt 5;
;FI;
; note: because “int #” instruction will use stack to store CS:IP and FLAGS,
; Push (FLAGS);
; Push(CS);
; Push(IP);
; have to allow on the stack for that much room 32 bits + 32 bits = 4 bytes + 4 bytes …
; from Programmer’s Reference Manual for INT instruction:
; REAL-ADDRESS-MODE:
; Push (FLAGS);
; IF = 0; (* Clear interrupt flag *)
; TF = 0; (* Clear trap flag *)
; Push(CS);
; Push(IP);
; (* No error codes are pushed *)
; CS := IDT[Interrupt number * 4].selector;
; IP := IDT[Interrupt number * 4].offset;
; from Programmer’s Reference Manual
; IRET (Return From Interrupt) returns control to an interrupted procedure. IRET differs from RET in that it also pops the flags from the stack into the flags register. The flags are stored on the stack by the interrupt mechanism.
%endif ; SAYHELLO
; SAFEWAY grocery …
%macro SAFECALL 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safecallinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
call %1
%endmacro
%macro SAFEPUSH 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safepushinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
push %1
%endmacro
%macro SAFEPOP 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safepopinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
pop %1
%endmacro
%macro SAFERET 1
; cmp SP, stacksegment
; jl safecallinterrupt
; saferetinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
ret %1
%endmacro
;%macro SAFEINT5 0
; my/your own interrupt 5 service routine
safeinterrupt5sr:
add [interrupt5count], 1
xor bl, bl
; mov byte bl, [stacktop – 4 * 2 + 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte bl, ‘I’ ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:90], bl ; ‘I ‘
mov byte bl, ‘N’ ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:92], bl ; ‘N ‘
mov byte bl, ‘T’ ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:94], bl ; ‘T ‘
mov byte bl, ‘5’ ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:96], bl ; ‘5 ‘
mov al, [interrupt5count]
call out1hex
; from Programmer’s Reference Manual
; IRET (Return From Interrupt) returns control to an interrupted procedure. IRET differs from RET in that it also pops the flags from the stack into the flags register. The flags are stored on the stack by the interrupt mechanism.
;ret
iret
;%endmacro ; SAFEINT5
;%macro SAFEINT9 0
; my/your own interrupt 9 service routine
safeinterrupt9sr:
add word [interrupt9count], 1
xor bl, bl
; mov byte bl, [stacktop – 4 * 2 + 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte bl, ‘I’ ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:100], bl ; ‘I ‘
mov byte bl, ‘N’ ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:102], bl ; ‘N ‘
mov byte bl, ‘T’ ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:104], bl ; ‘T ‘
mov byte bl, ‘9’ ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte [ES:106], bl ; ‘9 ‘
mov al, [interrupt9count]
call out1hex
call safeinterrupt9sr2
; from Programmer’s Reference Manual
; IRET (Return From Interrupt) returns control to an interrupted procedure. IRET differs from RET in that it also pops the flags from the stack into the flags register. The flags are stored on the stack by the interrupt mechanism.
;ret
iret
;%endmacro ; SAFEINT9
;%macro SAFEINT9 0
;keyboard input …
;for the screen, the messages in (“muo^n loa`i” ;(“muo^n loa`i va` key1 va` key2 va` … ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”)
; from Programmer’s Reference Manual
;The 80386 provides a separate I/O address space, distinct from physical memory, that can be used to address the input/output ports that are used for external 16 devices. The I/O address space consists of 2^(16) (64K) individually addressable 8-bit ports; any two consecutive 8-bit ports can be treated as a 16-bit port; and four consecutive 8-bit ports can be treated as a 32-bit port. Thus, the I/O address space can accommodate up to 64K 8-bit ports, up to 32K 16-bit ports, or up to 16K 32-bit ports.
;The program can specify the address of the port in two ways. Using an immediate byte constant, the program can specify:
;• 256 8-bit ports numbered 0 through 255.
;• 128 16-bit ports numbered 0, 2, 4, . . . , 252, 254.
;• 64 32-bit ports numbered 0, 4, 8, . . . , 248, 252.
;Using a value in DX, the program can specify: • 8-bit ports numbered 0 through 65535
;• 16-bit ports numbered 0, 2, 4, . . . , 65532, 65534
;• 32-bit ports numbered 0, 4, 8, . . . , 65528, 65532
;The 80386 can transfer 32, 16, or 8 bits at a time to a device located in the I/O space. Like doublewords in memory, 32-bit ports should be aligned at addresses evenly divisible by four so that the 32 bits can be transferred in a single bus access. Like words in memory, 16-bit ports should be aligned at even-numbered addresses so that the 16 bits can be transferred in a single bus access. An 8-bit port may be located at either an even or odd address.
;The instructions IN and OUT move data between a register and a port in the I/O address space. The instructions INS and OUTS move strings of data between the memory address space and ports in the I/O address space.
; from http://www.brokenthorn.com/Resources/OSDev19.html
;Keyboard Controller Ports
;Port Read/Write Descripton
;Keyboard Encoder
;0x60 Read Read Input Buffer
;0x60 Write Send Command
;Onboard Keyboard Controller
;0x64 Read Status Register
;0x64 Write Send Command
; following code for custom INT 9 service routine is from Randall Hyde’s Art of Assembly http://www.plantation-productions.com/Webster/www.artofasm.com/DOS/ch20/CH20-5.html
SetCmd:
push cx
push ax ;Save command value.
cli ;Critical region, no ints now.
; keyboard code following …. last weekend visit to saratoga to toilet with sign “wait 30 seconds between each flush”
; Wait until the 8042 is done processing the current command.
xor cx, cx ;Allow 65,536 times thru loop.
Wait4Empty: in al, 64h ;Read keyboard status register.
test al, 10b ;Input buffer full?
loopnz Wait4Empty ;If so, wait until empty.
; from Programmer’s Reference Manual
; LOOP (Loop While ECX Not Zero) is a conditional transfer that automatically decrements the ECX register
; before testing ECX for the branch condition. If ECX is non-zero, the program branches to the target label
; specified in the instruction. The LOOP instruction causes the repetition of a code section until the operation
; of the LOOP instruction decrements ECX to a value of zero. If LOOP finds ECX=0, control transfers to the
; instruction immediately following the LOOP instruction. If the value of ECX is initially zero, then the LOOP
; executes 2^(32) times.
;LOOPNE (Loop While Not Equal) and LOOPNZ (Loop While Not Zero) are synonyms for the same instruction.
; These instructions automatically decrement the ECX register before testing ECX and ZF for the branch conditions.
; If ECX is non-zero and ZF=0, the program branches to the target label specified in the instruction.
; If LOOPNE or LOOPNZ finds that ECX=0 or ZF=1, control transfers to the instruction immediately following the LOOPNE or LOOPNZ instruction.
; from Programmer’s Reference Manual
;TEST (Test) performs the logical “and” of the two operands, clears OF and CF, leaves AF undefined, and updates SF, ZF, and PF.
; The flags can be tested by conditional control transfer instructions or by the byte-set-on-condition instructions. The operands may be doublewords, words, or bytes.
; The difference between TEST and AND is that TEST does not alter the destination operand. TEST differs from BT in that TEST is useful for testing the value of multiple bits in one operations, whereas BT tests a single bit.
; from Programmer’s Reference Manual
;Status Flags’ Functions
;Bit Name Function
; 0 CF Carry Flag — Set on high-order bit carry or borrow; cleared
; otherwise.
; 2 PF Parity Flag — Set if low-order eight bits of result contain
; an even number of 1 bits; cleared otherwise.
; 4 AF Adjust flag — Set on carry from or borrow to the low order
; four bits of AL; cleared otherwise. Used for decimal
; arithmetic.
; 6 ZF Zero Flag — Set if result is zero; cleared otherwise.
; 7 SF Sign Flag — Set equal to high-order bit of result (0 is
; positive, 1 if negative).
;11 OF Overflow Flag — Set if result is too large a positive number
; or too small a negative number (excluding sign-bit) to fit in
; destination operand; cleared otherwise.
; Okay, send the command to the 8042:
pop ax ;Retrieve command.
out 64h, al
sti ;Okay, ints can happen again.
pop cx
ret ; end SetCmd
safeinterrupt9sr2:
push ds
push ax
push cx
;mov ax, 40h
mov ax, PROGRAMSEGMENT
mov ds, ax
mov al, 0ADh ;Disable keyboard
call SetCmd
cli ;Disable interrupts.
xor cx, cx
Wait4Data: in al, 64h ;Read kbd status port.
test al, 10b ;Data in buffer?
loopz Wait4Data ;Wait until data available.
in al, 60h ;Get keyboard data.
; cmp al, DelScanCode ;Is it the delete key?
; jne OrigInt9
; mov al, KbdFlags ;Okay, we’ve got DEL, is
; and al, AltBit or CtrlBit ; ctrl+alt down too?
; cmp al, AltBit or CtrlBit
; jne OrigInt9
; jmp OrigInt9
; echo keyboard data to screen …
call out2hex
; If ctrl+alt+DEL is down, just eat the DEL code and don’t pass it through.
mov al, 0AEh ;Reenable the keyboard
call SetCmd
mov al, 20h ;Send EOI (end of interrupt)
out 20h, al ; to the 8259A PIC.
pop cx
pop ax
pop ds
;iret
ret
; If ctrl and alt aren’t both down, pass DEL on to the original INT 9
; handler routine.
;OrigInt9: mov al, 0AEh ;Reenable the keyboard
; call SetCmd
;
; pop cx
; pop ax
; pop ds
;jmp cs:OldInt9
;%endmacro ; SAFEINT9
%macro DISPLAYREGISTERCHARACTERS 1
;displaycharacter:
xor BL, BL
;mov byte BL, al ;
mov byte BL, %1 ;
mov byte [ES:300], BL ; ‘H ‘
;ret ; displaycharacter
%endmacro ; DISPLAYCHARACTER
;%macro OUTPUTHEXNUMBER 0
; following code for input/output numbers is from http://www.ece.msstate.edu/~janem/ECE3724/S03/Presentations/number_io.ppt
out2hex: ; output value in ‘al’ as 2 hex character
;push byte AL ; save al
;push word AX ; save al
;push dword EAX ; save al
push AX ; save al
shr AL, 4 ; get most sig. 4 bits into lower
call out1hex ; print most sig. hex digit
pop AX ; get back original al
and AL, 0x0F ; upper 4 bits = 0 – working with low 4 bits
call out1hex ; print least sig. hex digit
ret
; from http://faydoc.tripod.com/cpu/jmp.htm :
;Description
; Transfers program control to a different point in the instruction stream without recording return information. The destination (target) operand specifies the address of the instruction being jumped to. This operand can be an immediate value, a general-purpose register, or a memory location.
;
;This instruction can be used to execute four different types of jumps:
; Near jump A jump to an instruction within the current code segment (the segment currently pointed to by the CS register), sometimes referred to as an intrasegment jump.
; Short jump A near jump where the jump range is limited to –128 to +127 from the current EIP value.
; Far jump A jump to an instruction located in a different segment than the current code segment but at the same privilege level, sometimes referred to as an intersegment jump.
; Task switch A jump to an instruction located in a different task.
;
;A task switch can only be executed in protected mode (see Chapter 6, Task Management, in the Intel Architecture Software Developer’s Manual, Volume 3, for information on performing task switches with the JMP instruction).
out1hex:
cmp AL, 0x09 ; is 4-bit value above 9 – i.e. a “number” 0-9
;jg skip ; jg “jump if greater” is signed, ja “jump if above” is unsigned
ja isCharacter ; if “greater than”, then must be a character
add AL, 0x30
;call displaycharacter
DISPLAYREGISTERCHARACTERS AL
ret
;;out1hexhigh:
;; cmp AH, 0x09 ; is 4-bit value above 9 – i.e. a “number” 0-9
;; ;jg skip ; jg “jump if greater” is signed, ja “jump if above” is unsigned
;; ja isCharacter ; if “greater than”, then must be a character
;; add AH, 0x30
;; ;call displaycharacter
;; DISPLAYREGISTERCHARACTERS AH
;; ret
isCharacter:
add AL, 0x37
;call displaycharacter
DISPLAYREGISTERCHARACTERS AL
ret
;out4hex:
; push AX ; save al
; shr AH, 4 ; get most sig. 4 bits into lower
; call out1hexhigh ; print most sig. hex digit
; pop AX ; get back original al
; and AH, 0x0F ; upper 4 bits = 0 – working with low 4 bits
; call out1hexhigh ; print least sig. hex digit
; push AX ; save al
; shr AL, 4 ; get most sig. 4 bits into lower
; call out1hex ; print most sig. hex digit
; pop AX ; get back original al
; and AL, 0x0F ; upper 4 bits = 0 – working with low 4 bits
; call out1hex ; print least sig. hex digit
; ret ; out4hex
;out32bithex:
; push EAX ; save EAX
; shr EAX, 16 ; get the most sig. 16 bits into lower
; call out4hex ;
; pop EAX ; restore EAX
; ;push EAX ; save EAX
; call out4hex
; ;pop EAX ; restore EAX
; ret ; out4hex
;%endmacro ; OUTPUTHEXNUMBER
exit:
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
; jmp hang
hang:
jmp hang ; or, equivalently in nasm: jmp $
hlt ; halt the system
; times 510-($-$$) db 0 ; 2 bytes less now; $ = beginning of current line/expression = “times”, $$ = beginning of current section = “hang:”
db 0x55
db 0xAA
;********************************************
;*** NOTE ***
; from arpaci dusseau http://pages.cs.wisc.edu/~remzi/OSTEP/vm-segmentation.pdf
;an idea was born, and it is called segmenta-
;tion. It is quite an old idea, going at least as far back as the very early
;1960’s [H61, G62]. The idea is simple: instead of having just one base
;and bounds pair in our MMU, why not have a base and bounds pair per
;logical segment of the address space?
;[G62] “Fact Segmentation”
;M. N. Greenfield
;Proceedings of the SJCC, Volume 21, May 1962
;Another early paper on segmentation; so early that it has no references to other work.
;[H61] “Program Organization and Record Keeping for Dynamic Storage”
;A. W. Holt
;Communications of the ACM, Volume 4, Issue 10, October 1961
;An incredibly early and difficult to read paper about segmentation and some of its uses.
; from http://en.wikipedia.org/wiki/THE_multiprogramming_system
; The THE multiprogramming system was a computer operating system designed by a team led by Edsger W. Dijkstra, described in monographs in 1965-66[1] and published in 1968.[2] Dijkstra never named the system; “THE” is simply the abbreviation of “Technische Hogeschool Eindhoven”, then the name (in Dutch) of the Eindhoven University of Technology of the Netherlands. The THE system was primarily a batch system[3] that supported multitasking; it was not designed as a multi-user operating system. It was much like the SDS 940, but “the set of processes in the THE system was static”.[3]
;The THE system apparently introduced the first forms of software-based memory segmentation (the Electrologica X8 did not support hardware-based memory management),[3] freeing programmers from being forced to use actual physical locations on the drum memory. It did this by using a modified ALGOL compiler (the only programming language supported by Dijkstra’s system) to “automatically generate calls to system routines, which made sure the requested information was in memory, swapping if necessary”.[3]
; from NASM manual:
;NASM gives special treatment to symbols beginning with a period. A label beginning with a single period is treated as a local label, which means that it is associated with the previous non-local label. So, for example:
;label1 ; some code
;.loop
; ; some more code
; jne .loop
; ret
;label2 ; some code
;.loop
; ; some more code
; jne .loop
; ret
;In the above code fragment, each JNE instruction jumps to the line immediately before it, because the two definitions of .loop are kept separate by virtue of each being associated with the previous non-local label.
;from http://wiki.osdev.org/Interrupts
; if IRQ 6 is sent to the PIC by a device, the PIC would tell the CPU to service INT 0Eh, which presumably has code for interacting with whatever device sent the interrupt in the first place. Of course, there can be trouble when two or more devices share an IRQ; if you wonder how this works, check out Plug and Play.
; from http://www.techmasala.com/2006/03/31/foundation-stone-3-bios-part-2-the-interrupt-vector-table/:
;Foundation stone #3 – BIOS part 2 – The interrupt vector table
;by Ramesh on Friday,March 31, 2006 @ 9:50 am
;In my post Foundation stone #2 we saw that BIOS is the one that takes in charge when you switch on your PC. After collecting the inventory of available and properly working hardware, the BIOS sets up what is called as the Interrupts area. An interrupt is a signal to the processor that there is something that needs its attention. As such each and every piece of hardware that is put together in your PC is useless unless it is orchestrated well. Take for example the keyboard, if the attention is not given at the right time when you press a key and reciprocated accordingly wherever you are then you can call the thing that is sitting in front of you as dumb
;So when the BIOS is done with the inventory of hardware, it initializes a memory space of 1024 bytes starting at 0000:0000h (this is a representation of memory location in the form of segment:offset in hexadecimal). An interrupt is a small routine or code that has the necessary details of the interrupt and occupies 4 bytes. So starting at memory location 0000:0000h interrupts are stored. So a total of 256 interrupts can be stored in a the allotted 1024 bytes but all is not being initialized by the BIOS. There are different types of interrupts, hardware interrupts, software interrupts, user interrupts and so on. The BIOS fills up the hardware interrupts and the software interrupts are mostly added by the OS.
;The Interrupt Vector Table (IVT) is a mapping of the interrupt number and the memory location in the form of segment:offset. This memory location contains the interrupt code for that particular interrupt. It is the responsibility of the OS to keep track of the IVT and monitor for interrupt and notify the processor. So what happens when you press a key or release a key, the keyboard send signals that contain information on what key was pressed or released. This gets stored in the memory location assigned for the keyboard interrupt (traditionally interrupt 09h is for keyboard). The OS which is constantly looking for these interrupts immediately captures the information and sends it for processing accordingly. The interrupt number and other details could differ from one BIOS manufacturer to other. You can get a lot of information about BIOS and interrupts from the BIOS central site.
; conventionally [c.f. http://en.wikipedia.org/wiki/Conventional_memory, http://en.wikipedia.org/wiki/Power-on_self-test%5D people agree upon the following memory map … from http://www.supernovah.com/Tutorials/Assembly2.php:
;Default Memory
;When the computer boots, the BIOS loads the memory with a lot of different data. This data resides in different places throughout memory and we are only left with 630Kb of memory to work with in the middle of everything. Here is a table showing the map of the memory directly after the computer boots:
;All ranges are inclusive
;Address Range (in hex) Size Type Description
;0 – 3FF 1Kb Ram Real Mode Interrupt Vector Table (IVT)
;400 – 4FF 256 bytes Ram BIOS Data Area (BDA)
;500 – 9FBFF 630Kb Ram Free Memory
;9FC00 – 9FFFF 1Kb Ram Extended BIOS Area (EBDA)
;A0000 – BFFFF 128Kb Video Ram VGA Frame Buffer
;C0000 – C7FFF 32Kb Rom Video Bios
;C8000 – EFFFF 160kb Rom Misc.
;F0000 – FFFFF 64Kb
; from NASM manual
;Multi-line macros are much more like the type of macro seen in MASM and TASM: a multi-line macro definition in NASM looks something like this.
;%macro prologue 1
; push ebp
; mov ebp,esp
; sub esp,%1
;%endmacro
; from http://www.husseinsspace.com/teaching/udw/1996/asmnotes/chaptwo.htm:
;The SHR/SLR instructions
;format:
;SHR destination,1
;SHR destination,CL
; SHL destination,1
; SHL destination,CL
;SHR shifts the destination right bitwise either 1 position or a number of positions determined by the current value of the CL register. SHL shifts the destination left bitwise either 1 position or a number of positions determined by the current value of the CL register. The vacant positions are filled by zeros.
;example:
;shr ax,1
; shl ax,1
;The first example effectively divides ax by 2 and the second example effectively multiplies ax by 2. These commands are faster than using DIV and MUL for arithmetic involving powers of 2.
;****************************
; from Intel Programmer’s Reference Manual
;10.1 Processor State After Reset
;The contents of EAX depend upon the results of the power-up self test. The self-test may be requested externally by assertion of BUSY# at the end of RESET. The EAX register holds zero if the 80386 passed the test. A nonzero value in EAX after self-test indicates that the particular 80386 unit is faulty. If the self-test is not requested, the contents of EAX after RESET is undefined.
;DX holds a component identifier and revision number after RESET as Figure 10-1 illustrates. DH contains 3, which indicates an 80386 component. DL contains a unique identifier of the revision level.
;Control register zero (CR0) contains the values shown in Figure 10-2 . The ET bit of CR0 is set if an 80387 is present in the configuration (according to the state of the ERROR# pin after RESET). If ET is reset, the configuration either contains an 80287 or does not contain a coprocessor. A software test is required to distinguish between these latter two possibilities.
;The remaining registers and flags are set as follows:
; EFLAGS =00000002H
; IP =0000FFF0H
; CS selector =000H
; DS selector =0000H
; ES selector =0000H
; SS selector =0000H
; FS selector =0000H
; GS selector =0000H
; IDTR:
; base =0
; limit =03FFH
;All registers not mentioned above are undefined.
;These settings imply that the processor begins in real-address mode with interrupts disabled.
;10.2 Software Initialization for Real-Address Mode
;In real-address mode a few structures must be initialized before a program can take advantage of all the features available in this mode.
;10.2.1 Stack
;No instructions that use the stack can be used until the stack-segment register (SS) has been loaded. SS must point to an area in RAM.
;10.2.2 Interrupt Table
;The initial state of the 80386 leaves interrupts disabled; however, the processor will still attempt to access the interrupt table if an exception or nonmaskable interrupt (NMI) occurs. Initialization software should take one of the following actions: Change the limit value in the IDTR to zero. This will cause a shutdown if an exception or nonmaskable interrupt occurs. (Refer to the 80386 Hardware Reference Manual to see how shutdown is signalled externally.)
; Put pointers to valid interrupt handlers in all positions of the interrupt table that might be used by exceptions or interrupts.
; Change the IDTR to point to a valid interrupt table.
;
;10.2.3 First Instructions
;After RESET, address lines A{31-20} are automatically asserted for instruction fetches. This fact, together with the initial values of CS:IP, causes instruction execution to begin at physical address FFFFFFF0H. Near (intrasegment) forms of control transfer instructions may be used to pass control to other addresses in the upper 64K bytes of the address space. The first far (intersegment) JMP or CALL instruction causes A{31-20} to drop low, and the 80386 continues executing instructions in the lower one megabyte of physical memory. This automatic assertion of address lines A{31-20} allows systems designers to use a ROM at the high end of the address space to initialize the system.
; from http://en.wikipedia.org/wiki/Interrupt_descriptor_table
;In the 8086 processor, the IDT resides at a fixed location in memory from address 0x0000 to 0x03ff, and consists of 256 four-byte real mode pointers (256 × 4 = 1024 bytes of memory). In the 80286 and later, the size and locations of the IDT can be changed in the same way as it is done in protected mode, though it does not change the format of it. A real mode pointer is defined as a 16-bit segment address and a 16-bit offset into that segment. A segment address is expanded internally by the processor to 20 bits thus limiting real mode interrupt handlers to the first 1 megabyte of addressable memory. The first 32 vectors are reserved for the processor’s internal exceptions, and hardware interrupts may be mapped to any of the vectors by way of a programmable interrupt controller.
; A commonly used x86 real mode interrupt is INT 10, the Video BIOS code to handle primitive screen drawing functions such as pixel drawing and changing the screen resolution.
; from http://software.intel.com/en-us/articles/introduction-to-x64-assembly
; XOR EAX, EAX ; zero out eax
; MOV ECX, 10 ; loop 10 times
;Label: ; this is a label in assembly
; INX EAX ; increment eax
; LOOP Label ; decrement ECX, loop if not 0
; from https://courses.engr.illinois.edu/ece390/books/artofasm/CH06/CH06-5.html#HEADING5-294
; mov ecx, 255
;ArrayLp: mov Array[ecx], cl
; loop ArrayLp
; mov Array[0], 0
;The last instruction is necessary because the loop does not repeat when cx is zero. Therefore, the last element of the array that this loop processes is Array[1], hence the last instruction.
; The loop instruction does not affect any flags.
; 2.17.2014 chu’ Ha^n telephoned about obtaining literature on American Philosophy and on US Census Data particularly
; US Census Data on black population expansion into US and into the world …
; following day: couple resembling co^ Be^ and David Lowe seen at Post Office when we tried to mail chu’ Kha’s preserved fruit to father in Michigan
; from http://randomascii.wordpress.com/2012/12/29/the-surprising-subtleties-of-zeroing-a-register/
; also see http://navet.ics.hawaii.edu/~casanova/courses/ics312_spring14/slides/ics312_bits_2.pdf
;Tabula rasa
;The x86 instruction set does not have a special purpose instruction for zeroing a register. An obvious way of dealing with this would be to move a constant zero into the register, like this:
;mov eax, 0
;That works, and it is fast. Benchmarking this will typically show that it has a latency of one Sandybridge diecycle the result can be used in a subsequent instruction on the next cycle. Benchmarking will also show that this has a throughput of three-per-cycle. The Sandybridge documentation says that this is the maximum integer throughput possible, and yet we can do better.
;Its too big
;The x86 instruction used to load a constant value such as zero into eax consists of a one-byte opcode (0xB8) and the constant to be loaded. The problem, in this scenario, is that eax is a 32-bit register, so the constant is 32-bits, so we end up with a five-byte instruction:
;B8 00 00 00 00 mov eax, 0
;Instruction size does not directly affect performance you can create lots of benchmarks that will prove that it is harmless but in most real programs the size of the code does have an effect on performance. The cost is extremely difficult to measure, but it appears that instruction-cache misses cost 10% or more of performance on many real programs. All else being equal, reducing instruction sizes will reduce i-cache misses, and therefore improve performance to some unknown degree.
;Smaller alternatives
;Many RISC architectures have a zero register in order to optimize this particular case, but x86 does not. The recommended alternative for years has been to use xor eax, eax. Any register exclusive ored with itself gives zero, and this instruction is just two bytes long:
;33 C0 xor eax, eax
;Careful micro-benchmarking will show that this instruction has the same one-cycle latency and three-per-cycle throughput of mov eax, 0 and it is 60% smaller (and recommended by Intel), so all is well.
;Suspicious minds
;If you really understand how CPUs work then you should be concerned with possible problems with using xor eax, eax to zero the eax register. One of the main limitations on CPU performance is data dependencies. While a Sandybridge processor can potentially execute three integer instructions on each cycle, in practice its performance tends to be lower because most instructions depend on the results of previous instructions, and are therefore serialized. The xor eax, eax instruction is at risk for such serialization because it uses eax as an input. Therefore it cannot (in theory) execute until the last instruction that wrote to eax completes. For example, consider this code fragment below:
;1: add eax, 1
;2: mov ebx, eax
;3: xor eax, eax
;4: add eax, ecx
;Careful micro-benchmarking will show that this instruction has the same one-cycle latency and three-per-cycle throughput of mov eax, 0 and it is 60% smaller (and recommended by Intel), so all is well.
;Ideally we would like our awesome out-of-order processor to execute instructions 1 and 3 in parallel. There is a literal data dependency between them, but a sufficiently advanced processor could detect that this dependency is artificial. The result of the xor instruction doesnt depend on the value of eax, it will always be zero.
;It turns out that for x86 processors have for years handled xor of a register with itself specially. Every out-of-order Intel and AMD processor that I am aware of can detect that there is not really a data dependency and it can execute instructions 1 and 3 in parallel. Which is great. The CPUs use register renaming to create a new eax for the sequence of instructions starting with instruction 3.
; from http://stackoverflow.com/questions/4909563/why-should-code-be-aligned-to-even-address-boundaries-on-x86
;Because the (16 bit) processor can fetch values from memory only at even addresses, due to its particular layout: it is divided in two “banks” of 1 byte each, so half of the data bus is connected to the first bank and the other half to the other bank. Now, suppose these banks are aligned (as in my picture), the processor can fetch values that are on the same “row”.
; bank 1 bank 2
;+——–+——–+
;| 8 bit | 8 bit |
;+——–+——–+
;| | |
;+——–+——–+
;| 4 | 5 | ;+——–+——–+
;| 2 | 3 |
;+——–+——–+
;| 0 | 1 |
;+——–+——–+
; \ / \ /
; | | | |
; | | | |
; data bus (to uP)
;Now, since this fetch limitation, if the cpu is forced to fetch values which are located on an odd address (suppose 3), it has to fetch values at 2 and 3, then values at 4 and 5, throw away values 2 and 5 then join 4 and 3 (you are talking about x86, which as a little endian memory layout).
; That’s why is better having code (and data!) on even addresses.
;PS: On 32 bit processors, code and data should be aligned on addresses which are divisible by 4 (since there are 4 banks).
;Hope I was clear. 🙂
;share|improve this answer
;answered Feb 5 ’11 at 23:02
;BlackBear
;9,42131746
;bio
;website google.it
;location Trento, Italy
;age 19
; from http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/
;Conclusion: On recent Intel processors, data alignment does not make processing measurably faster. Data alignment for speed is a myth.
;Acknowledgement: I am grateful to Owen Kaser for pointing me to the references on this issue.
;http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/
;\[ d E S F a s a d o \]
;11/9/99
;DOS: nasm -f bin -o your_file.com your_file.asm
;1)mov ax,your_segment
; mov ds,ax
;2) mov ax,[your_segment]
; mov ds,ax
;first of all you cant use mov ds,something… secondly you are trying to put
;in DS an offset of the current CS.
;The second example is what you have to do.
;hope this help..
;–
;[ yOu HaVe To SeArCh AnD sEaRcH, rElAtE iNfO, pRoBe AnD pRobE, tHeRe Is NoT
;aNoThEr WaY ]
;[ dOnT nEvEr gIvE uP, uSe YoR bRaIn At LeAsT aT 1o0% ]
;ASM CodER, PC HW & Electrical Technitian
;desf…@ciudad.com.ar
;http://members.xoom.com/desfasado >>> dENarixs OS Project
;UIN: 30796163
; from http://devdocs.inightmare.org/x86-assembly-changing-interrupt-vector-table/
;(x86 Assembly) Changing Interrupt Vector Table
;(This tutorial was originally written in 2004 and featured in http://asm.inightmare.org/)
;Another thing I want to write tutorial is about changing interrupts. There are two ways you can do that using DOS interrupts and modifying interrupt vector table directly. Both ways are pretty simple, you need to know these DOS interrupts (int 21h):
;Function
;What does it do?
;Parameters
;AH = 25h Set interrupt vector AL – interrupt number to change
; DS:DX – pointer to interrupt function
;AH = 35h Get interrupt vector. Gets address of currently set interrupt. AL – interrupt number
; Returns:
; ES:BX – pointer to interrupt
;AH = 4Ch Exits DOS program 😉 AL – exit code (not sure what it does)
;It’s pretty simple, just take a look at the sample code here.
;The other way to make your own interrupt is to modify interrupt vector table directly. It’s mapped from 0000:0000 to 0000:0400h in memory. The structure is very simple:
;Offset
;Segment
;Int 0
;(Offset 0000)
;(Offset 0002)
;Int 1
;(Offset 0004)
;(Offset 0006)
;Int 2
;(Offset 0008)
;(Offset 0010)
;…
;…
;So getting interrupt offset is:
;mov ax, [intnum*4]
;And segment:
;mov ax [intnum*4+2]
;Setting:
;mov ax, [intnum*4] ; offset
;mov ax [intnum*4+2] ; segment
;Well and how to call the interrupt, I think we all know:
;int intnum
;Everything is pretty simple. NASM source code:
;DOS interrupt version – here
; Direct modifiying of intvec table – here
; from http://asm.inightmare.org/ints_vec.asm
; org 100h
;xor ax, ax
;mov es, ax
; Save interrupt address so we can restore it later
;mov bx, [es:69h*4]
;mov [old_int_off], bx
;mov bx, [es:69h*4+2]
;mov [old_int_seg], bx
; modify interrupt vector table on 0x69th entry to point to our interrupt
;mov dx, int_prog
;mov [es:69h*4], dx
;mov ax, cs
;mov [es:69h*4+2], ax
;nop
;int 69h ; execute our interrupt
;restore old interrupt
;mov ax, [old_int_seg]
;mov [es:69h*4+2], ax
;mov dx, [old_int_off]
;mov [es:69h*4], dx
;mov ax, 0x4c00 ; Exit
;int 21h
; Our interrupt just prints some text 🙂
;int_prog:
;pusha ; save old registers, just incase 😉
;mov ah, 9
;mov dx, our_text
;int 21h
;popa
;iret
;our_text db “Bleh… $”
;old_int_seg dw 0
;old_int_off dw 0
; from http://www.ece.msstate.edu/~janem/ECE3724/S03/Presentations/number_io.ppt
;This is the html version of the file http://www.ece.msstate.edu/~janem/ECE3724/S03/Presentations/number_io.ppt.
;Google automatically generates html versions of documents as we crawl the web.
;1
;Ways to Handle I/O (Input/Ouput)
;•For Output
;◦Use Irvine16 Functions
;◾Writechar, WriteBin, WriteInt, Writehex, Writestring
;◦Use DOS (Int 21h) Functions – (Table C-2)
;◾2 – write char, 6 – write char, 9- write string (Table C-3)
;◦Use Video BIOS (Int 10h) Functions
;◾9 – write char and attribute, 0A- write char, …
;•For Input
;◦Use Irvine16 Functions
;◾Readchar, Readint, ReadHex, Readstring
;◦Use DOS (Int 21h) Functions (Table C-2)
;◾1 – read char, 6 – read char, 7- read char
;◦Use Keyboard BIOS (Int 16h) Functions (Table C-5)
;◾10 – wait for key
;2
;Input/Output of Numbers
;•A common task is to input or output numbers in ASCII format
;•Output tasks:
;◦Output an 8-bit value as ASCII string in HEX format
;◦Output an 8-bit value as a ASCII string in BINARY format (see ‘pbin.asm’ example on WWW page)
;◦Output an 8-bit value as ASCII string in DECIMAL format
;•Input tasks:
;◦Input a string representing an 8-bit number in Hex format
;◦Input a string representing an two digit decimal number (unsigned)
;
;3
;Output an 8 bit number in Hex Format
;•Two Hex characters in 8-bits. Want to work with each set of 4-bits individually.
;•Each Hex character represents 4-bits in a number.
;◦0000 = ‘0’ (ASCII code = 30h)
;◦0001 = ‘1’ (ASCII code = 31h)
;◦1001 = ‘9’ (ASCII code = 39h)
;◦……
;◦1010 = ‘A’ (ASCII code = 41h)
;◦1011 = ‘B’ (ASCII code = 42h)
;◦……
;◦1111 = ‘F’ (ASCII code) = 46h ).
;•If 4-bits is between 0-9, then ASCII = 30h + 4bits
;•If 4-bits is between A-F, then ASCII = 37h + 4bits
;4
;Output an 8 bit number in Hex Format
;Approach: Write a subroutine called ‘Out1Hex’. This will output the lower 4 bits of register ‘AL’ as an Hex digit to the screen.
;To output an 8-bit value, the main routine(out2hex) will call ‘Out1Hex’ twice 1) for the most significant HEX digit, and
; 2) for the least significant Hex digit.
; out2hex proc
;; output value in ‘al’ as 2 hex character
; push ax ; save al
; shr al, 4 ; get most sig. 4 bits into lower
; call Out1Hex ; print most sig. hex digit
; pop ax ; get back original al
; and al, 0x0Fh ; upper 4 bits = 0 – working with low 4 bits
; call Out1Hex ; print least sig. hex digit
; out2hex endp
;5
;Out1Hex
;Pseudo code for Out1Hex:
;
; if ( AL > 09H) jump to SKIP
; AL = AL + 30H
; Use Int21H, function2 to print character
; return
;
; skip: AL = AL + 37H
; Use Int21H, function2 to print character
; return
;
;
;6
; from Programmer’s Reference Manual
; CMP (Compare) subtracts the source operand from the destination operand. It updates OF, SF, ZF, AF, PF, and CF but does not alter the source and destination operands. A subsequent Jcc or SETcc instruction can test the appropriate flags.
; from
;Out1Hex
;A procedure to convert a 4-bit hex number to ASCII and print the character to the screen.
;Out1hex proc
;Cmp al, 9 ;is 4-bit value above 9?
;Ja ischar ;if so, must be a character
;Add al, 30h ;if not, add 30h for conversion
;Jmp printit ;go to print label
;Ischar: add al, 37h ;was character – add 37h for ;conversion
;Printit: mov dl, al ;printing a character to screen
;Mov ah,2 ;using int 21h, function 2.
;Int 21h
;Ret ;return to main procedure
;Out1hex endp
;End Main
;7
;Output a 16-bit hex number? 32 bits?
;•How would you print out a 16 bit value?
;◦Call Out1Hex 4 times.
;◦Each call would have to have the 4 bits in the lower four bits of AL
;◦You would have to start with the Most significant bits
;◦After saving the value, use shr instruction to get the correct bits.
;•How would you printout a 32-bit value?
;◦Call ‘Out1Hex’ 8 times – once for each 4 bits of the 32-bit value.
;8
;Output an 8-bit number in Decimal Format
;•How would you output a number in Decimal format?
;•Assume that AL contains a value between 0 and 99 and you want to print this out as a decimal value
;•The value of the first digit is ‘AL divided by 10’ (quotient value of AL/10).
;•The value of the 2nd digit is REMAINDER of AL divided by 10!!
;9
;Out1Dec
;A procedure to convert an 8-bit unsigned decimal number stored in AL to ASCII and print the character to the screen.
;Out1Dec Proc
;Push ax ;save value
;And ah, ah ;clear ah
;Div 10 ;divide value by 10 (quotient in AL, ;remainder in AH)
;Add al, 30h ;convert 10’s digit to ASCII
;Call printchar
;Mov al, ah ;get 1’s digit
;Add al, 30h ;convert to ASCII
;Call printchar
;Out1Dec Endp
;10
;Input an 8-bit number in HEX format
;•An 8-bit hex number will require two ASCII characters to represent it
;•Need to get 4-bit value of digit from ASCII character code
;•If ASCII is between 30H and 39H (‘0’ and ‘9’), then four-bit value is ASCII value – 30H.
;•If ASCII is between 41H and 46H (‘A’ and ‘F’), then four-bit value is ASCII value – 37H
;11
;Input an 8-bit number in HEX format
;Assume AX has the two ASCII digits that represent a HEX number
;Example: AX = 4335 h, AH = 43h = ‘C’, AL=35h = ‘5’.
;Want to convert this to AL = C5h.
; in2hex proc
; push ax ;; save AX
; mov al,ah ;; get most sig. char into AL
; call inhex ;; convert ASCII hex code in AL to 4 bit value
; mov bl, al ;; save in BL
; pop ax ;; get AX back
; call inhex ;; convert ASCII hex code in AL to 4-bit value
; shl bl,4 ;; shift bl to left to move lower 4bit to upper
; or al, bl ;; combine upper and lower bits, AL has value!
; ret
; in2hex endp
;12
;inhex Subroutine
;Want to convert the ASCII code in AL that is a HEX digit to its 4-bit value
; Pseudo code: if (AL > 39h) jump to skip
; AL = AL – 30h
; return
; skip: AL = AL – 37H
; return
;13
;Input an 8-bit number in Decimal format
;Assume AX has the two ASCII digits that represent a DECIMAL number
;Example: AX = 3731 h, AH = 38h = ‘7’, AL=31h = ‘1’.
;Want to convert this to AL = 71 (decimal) = 47h !!
; Approach:
; a. Convert the most significant ASCII digit to its four bit value.
; b. Multiply this by 10 and save.
; c. Convert the least significant ASCII digit to its four bit value and ADD it to the value produced in ‘b’!!
; 71 = 7 * 10 + 1 = 71 = 47 h.
NASM/love is blind
3.16.2014
there was a program on the internet written entirely using NASM pseudo-op “db”.
for example, the following programs identical bit patterns I the .bin file output and therefore are equivalent:
Program 1:
[BITS 16]
ORG 0x7C00
jmp $
times 510 – ($ – $$) db 0
dw 0xAA55
Program 2:
[BITS 16]
ORG 0x7C00
;jmp $
dw 0xfeeb
times 510 – ($ – $$) db 0
dw 0xAA55
making a difference or to each his own
different strokes for different folks …. with application to chu’ Hoa`ng’s recent heart problems …
Ecclesiastes “there’s nothing new/difference under the sun” … and yet one has to make an effort at creating the illusion of difference/newness … by making a difference maintaining a zero-footprint path …
from testNASM.asm:
; song “I hope when you decide, kindness will be your guide …”:
; “I did not program you, you program you: cha me. sinh con tro+`i sinh ti’nh/compute/program:
; I program/vote/wish/love/aim ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’, and
; Everything/All/Allah/Nature/God programs/votes/wishes/loves/aims/’muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’, and
; the rest, what’s in between God and I is you is up to you … hopefully you too will program along with God and I for
; ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ ….
sandboxes
testNASM
; boot.asm
; bin version
; song “I hope when you decide, kindness will be your guide …”:
; “I did not program you, you program you: cha me. sinh con tro+`i sinh ti’nh/compute/program:
; I program/vote/wish/love/aim ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’, and
; Everything/All/Allah/Nature/God programs/votes/wishes/loves/aims/’muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’, and
; the rest, what’s in between God and I is you is up to you … hopefully you too will program along with God and I for
; ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well’ ….
;from NASM manual:
; The BITS directive specifies whether NASM should generate code designed to run on a processor operating in 16-bit mode, 32-bit mode or 64-bit mode.
; You do not need to specify BITS 32 merely in order to use 32-bit instructions in a 16-bit DOS program; if you do, the assembler will generate incorrect code because it will be writing code targeted at a 32-bit platform, to be run on a 16-bit one:
; When NASM is in BITS 16 mode, instructions which use 32-bit data are prefixed with an 0x66 byte, and those referring to 32-bit addresses have an 0x67 prefix. In BITS 32 mode, the reverse is true: 32-bit instructions require no prefixes, whereas instructions using 16-bit data need an 0x66 and those working on 16-bit addresses need an 0x67.
; When NASM is in BITS 64 mode, most instructions operate the same as they do for BITS 32 mode.
[BITS 16]
; from the Programmer’s Reference Manual
;The segment containing the currently executing sequence of instructions is known as the current code segment;
;it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using
;as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment
;control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.
;The instruction pointer register (EIP) contains the offset address, relative to the start of the current code
;segment, of the next sequential instruction to be executed. The instruction pointer is not directly visible
;to the programmer; it is controlled implicitly by control-transfer instructions, interrupts, and exceptions.
;As Figure 2-9 shows, the low-order 16 bits of EIP is named IP and can be used by the processor as a unit.
;This feature is useful when executing instructions designed for the 8086 and 80286 processors.
; from http://www.supernovah.com/Tutorials/BootSector2.php
;As stated earlier, we cannot be sure if the BIOS set us up with the starting address of 0x7C0:0x0 or 0x0:0x7C00.
;We will use the second segment offset pair to execute our boot sector so we know for sure how the CPU will access
;our code. To do this, our very first instruction will be a far jump that simply jumps to the next instruction.
;The trick is, if we specify a segment, even if it is 0x0, the jmp will be a far jump and the CS register will be
;loaded with the value 0x0 and the IP register will be loaded with the address of the next instruction to be
;executed.
;[BITS 16]
;[ORG 0x7C00]
;jmp 0x0:Start
;Start:
; This code will set the CS segment to 0x0, set the IP register to the the very next instruction which will be slightly past 0x7C00, ….
; universal-loop
; {
; start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // in “gia ba?o”, “ba?o” ~ maintain as in “ba?o thu?/to^`n” …
; try/if ;// tin messages …. the try/if is the “gia” of “gia ba?o” …
; maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // the message “stack” is loaded or push-pop with messages …; // push-and-pop-or-sent-and-receive (&messageNEW-hay-tinLA`NH); // tin and shakespeare’s version of “all roads lead to rome”: “doubt thou the stars are fire doubt truth to be a liar but never doubt I loved ‘muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well'”: 1/19/2014 Sunday Service … Gospel ~ Good News Tin La\nh …”Gia Ba?o”: the “gia” attempts to reach an agreement with the “ba?o” …// salinger on internet news: push/pop/create stack/heap by an expansion assignment (“muo^n loa`i” ; ;catch/else ;// unmaintainable tin/messages or kho’ tin hay kho^ng tin no messages … SBTN Uye^n Thi. commercial for MBR [master boot record] “kho’ tin nhu+ng co’ tha^.t …”
; ; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
; }
; irish-catholic Pat Benatar song “heartbreaker, dreammaker, don’t you mess around with me …” ….
; perhaps “there’s beggary in a love that can be reckoned” when love is unconditional–gia ba?o chu’ hoa`ng to^n an hoa`ng phi hu`ng and 10 commandments–but
; the ten commandments say there’s a love that’s conditional … and the 10 commandments describe the limits or conditions of that love …
; from http://wiki.osdev.org/Babystep2:
;some say that the bootloader is loaded at [metaphorical address] 0000:7C00, while others say 07C0:0000.
;This is in fact the same [real] address: 16 * 0x0000 + 0x7C00 = 16 * 0x07C0 + 0x0000 = 0x7C00.
;%define ORIGIN ; ….. comment this out to use “org 0” instead of “org 0x07C0” …
%ifdef ORIGIN
[ORG 0x7c00]
;segment .text align=16
; segment:offset … ds:offset or cs:offset … 0:offset-from-0x7COO … that is, labels in code following is addressed as 0:0x7C00+offset-from-start-of-file
;Following code will set the CS segment to 0x0, set the IP register to the the very next instruction which will be slightly past 0x7C00, ….
jmp 0x0:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
%else ;
[ORG 0]
;segment .text align=16
; segment:offset … ds:offset or cs:offset … 0x07C0:offset-from-0 … that is, labels in the code following is addressed as 0x07C0:0+offset-from-start-of-file
;Following code will set the CS segment to 0x07C0, set the IP register to the the very next instruction which will be slightly past 0x0, ….
jmp 0x07C0:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
%endif ; ORIGIN
%ifdef ORIGIN
%define MEMORYSEGMENTREALLOWBOUND 0x7C00
%else
%define MEMORYSEGMENTREALLOWBOUND 0x0000
%endif ; ORIGIN
%define SEGMENTSIZE 512
%define MEMORYSEGMENTREALUPPERBOUND MEMORYSEGMENTREALLOWBOUND + SEGMENTSIZE
; data segment
; section .data
;section datasegment align=16 ; start= follows=
;segment datasegment align=16 ; start= follows=
; align 16
;segment .data align=16
;datasegment dw 123
datasegment db ‘Hope Well’
; stack segment
; section .bss
; section stacksegment align=16 ; start= follows=
; segment stacksegment align=16 ; start= follows=
; align 16
;segment .stack align=16
stacksegment resb 64
stacktop:
spprevious dw 0
spnew dw 0
spcounter times 10 dw 0
; from NASM manual
;message db ‘hello, world’
;msglen equ $-message
;stacktop = stacksegment – datasegment + 64
;segment .text align=16
; set up the data, stack, etc. segment registers
;segment .text align=16
start:
;mov AX, 0x0
;mov AX,seg DATASEGMENT1
;; mov AX, datasegment
;; mov AX, seg datasegment ; error: binary output format does not support segment base references
;; mov AX, [datasegment]
%ifdef ORIGIN
mov AX, 0x0
; mov AX, 0x0 + datasegment
mov DS,AX
; from http://www.supernovah.com/Tutorials/BootSector2.php
; The processor uses the SS:SP segment offset address to determine the location of the stack.
; from http://wiki.osdev.org/Stack:
;Take care when implementing your kernel. If you use segmentation, the DS segment should be configured to have it’s base at the same address as SS does. Otherwise you may run into problems when passing pointers to local variables into functions, because normal GPRs can’t access the stack the way you might think.
;mov AX,seg STACKSEGMENT
;mov AX, 0x0 + stacksegment
mov AX, 0x0
mov SS,AX
mov SP, 0x0 + stacktop
%else
; mov AX, 0x07C0 + datasegment
; mov AX, datasegment
mov AX, 0x07C0
mov DS,AX
; from http://www.supernovah.com/Tutorials/BootSector2.php
; The processor uses the SS:SP segment offset address to determine the location of the stack.
; from http://wiki.osdev.org/Stack:
;Take care when implementing your kernel. If you use segmentation, the DS segment should be configured to have it’s base at the same address as SS does. Otherwise you may run into problems when passing pointers to local variables into functions, because normal GPRs can’t access the stack the way you might think.
;mov AX,seg STACKSEGMENT
; mov AX, 0x07C0 + stacksegment
;mov AX, stacksegment
mov AX, 0x07C0
mov SS,AX
; mov SP, 0x07C0 + stacktop
mov SP, stacktop
; from http://frz.ir/dl/tuts/8086_Assembly.pdf
;MOV REG, memory
;MOV memory, REG
;MOV REG, REG
;MOV memory, immediate
;MOV 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…
; mov CX, SP
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter], spprevious – spnew
%endif ; ORIGIN
;mov AX,seg STACKSEGMENT
; mov AX, stacksegment
; mov SS,AX
; mov SP,stacktop
; to use the stack, use “call” and “ret” instead of “jmp”
; effectively, the illegal “mov eip, label” ~ legal “jmp label”
; or just let the program flows, without the jmp, to instructions that follow
; jmp main ; jmp Loads EIP with the specified address
; PUSH instruction from programmer’s reference manual
;IF StackAddrSize = 16
;THEN
; IF OperandSize = 16 THEN
; SP := SP – 2;
; (SS:SP) := (SOURCE); (* word assignment *)
; ELSE
; SP := SP – 4;
; (SS:SP) := (SOURCE); (* dword assignment *)
; FI;
;ELSE (* StackAddrSize = 32 *)
; IF OperandSize = 16
; THEN
; ESP := ESP – 2;
; (SS:ESP) := (SOURCE); (* word assignment *)
; ELSE
; ESP := ESP – 4;
; (SS:ESP) := (SOURCE); (* dword assignment *)
; FI;
;FI;
; RET instruction
;IF instruction = near RET
;THEN;
; IF OperandSize = 16
; THEN
; IP := Pop();
; EIP := EIP AND 0000FFFFH;
; ELSE (* OperandSize = 32 *)
; EIP := Pop();
; FI;
; IF instruction has immediate operand THEN eSP := eSP + imm16; FI;
;FI
; CALL instruction
;IF rel16 or rel32 type of call
;THEN (* near relative call *)
; IF OperandSize = 16
; THEN
; Push(IP);
; EIP := (EIP + rel16) AND 0000FFFFH;
; ELSE (* OperandSize = 32 *)
; Push(EIP);
; EIP := EIP + rel32;
; FI;
;FI;
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; mov [spprevious], SP
call main ; call = push + jmp; ret = pop + jmp
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; from http://wiki.osdev.org/Babystep2:
; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
; of segment and offset that point to the same address.
%define REALADDRESS(SEGMENTNO,OFFSETNO) SEGMENTNO*16+OFFSETNO
%define VERIFYSEGMENTADDRESSBOUND(SEGMENTADDRESSTOVERIFY, OFFSETADDRESSTOVERIFY) \
(REALADDRESS(SEGMENTADDRESSTOVERIFY,OFFSETADDRESSTOVERIFY) > MEMORYSEGMENTREALLOWBOUND) \
& (REALADDRESS(SEGMENTADDRESSTOVERIFY,OFFSETADDRESSTOVERIFY) < MEMORYSEGMENTREALUPPERBOUND)
; generate some virtual segment:offset address for use with a real address …
; TO DO: align the generated addresses to “natural” byte boundaries …
; %define GENERATESEGMENTADDRESS(REALADDRESSNO, &GENSEGMENTNO, &GENOFFSETNO) …………….
; %define GENERATEVIRTUALSEGMENTADDRESS(REALADDRESSNO, VIRTUALOFFSETADDRESSINPUT) (REALADDRESSNO – VIRTUALOFFSETADDRESSINPUT)/16
; %define GENERATEOFFSETNO(REALADDRESSNO, VIRTUALSEGMENTADDRESSINPUT) (REALADDRESSNO – VIRTUALSEGMENTADDRESSINPUT * 16)
; from http://geezer.osdevbrasil.net/johnfine/segments.htm:
;The way it really works
; Each segment register is really four registers: A selector register
;A base register
;A limit register
;An attribute register
;
;In all modes, every access to memory that uses a segment register uses the base, limit, and attribute portions of the segment register and does not use the selector portion.
;Every direct access to a segment register (PUSHing it on the stack, MOVing it to a general register etc.) uses only the selector portion. The base, limit, and attribute portions are either very hard or impossible to read (depending on CPU type). They are often called the “hidden” part of the segment register because they are so hard to read.
;Intel documentation refers to the hidden part of the segment register as a “descriptor cache”. This name obscures the actual behavior of the “hidden” part.
; In real mode (or V86 mode), when you write any 16-bit value to a segment register, the value you write goes into the selector and 16 times that value goes into the base. The limit and attribute are not changed.
;In pmode, any write to a segment register causes a descriptor to be fetched from the GDT or LDT and unpacked into the base, limit and attribute portion of the segment register. (Special exception for the NULL Selector).
;When the CPU switchs between real mode and pmode, the segment registers do not automatically change. The selectors still contain the exact bit pattern that was loaded into them in the previous mode. The hidden parts still contain the values they contained before, so the segment registers can still be used to access whatever segments they refered to before the switch.
;Writes to a segment register
;When I refer to “writing to a segment register”, I mean any action that puts a 16-bit value into a segment register.
;The obvious example is something like:
; MOV DS,AX
;However the same rules apply to many other situations, including: POP to a segment register.
;FAR JMP or CALL puts a value in CS.
;IRET or FAR RET puts a value in CS.
;Both hardware and software interrupts put a value in CS.
;A ring transition puts a value in both SS and CS.
;A task switch loads all the segment registers from a TSS.
; from the Programmer’s Reference Manual
;The segment containing the currently executing sequence of instructions is known as the current code segment;
;it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using
;as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment
;control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.
main:
; to use the stack, use “call” and “ret” instead of “jmp”
;jmp screensetup ; or just let the program flows, without the jmp, to instructions that follow
call screensetup
call clearscreenpixels
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; mov [spprevious], SP
call sayhello
; mov [spnew], SP
; mov word [spcounter + 2 * 1], spprevious – spnew
call exit
call hang
ret ; return
; from http://www.supernovah.com/Tutorials/BootSector4.php:
;Video Memory
;As previously stated, what is printed to the screen is simply controlled by a special section of memory called
;the video memory (or VGA memory). This section of memory is then periodically copied to the video device
;memory which is then presented to the screen by the Digital Analog Converter (DAC). Currently we are in text
;mode 03h which is a form of EGA. The video memory for text mode 3h begins at 0xB8000. Text mode 03h is 80 characters wide
;and 25 characters tall. This gives us 2000 total characters (80 * 25). Each character consists of 2 bytes which
;yields 4000 bytes of memory in total. So this means that text mode 03h stores it’s video information (the information that is
;printed to the screen) at the memory address 0xB8000 and it takes up 4000 bytes of memory.
;Printing Character to the Screen
;The first we must do in order to print character to the screen is to get a segment register setup that points
;to the memory location 0xB8000 [= 753664 = 47104 * 16]. Remember that segments in real mode have the lower four bits implicitly
;set to zero and because each hex digit represents four bits we can easily drop the right most zero on the
;memory address when storing it in a segment register. We will use the ES segment register because we
;still want to access our data with the DS segment so we don’t run into problems when using instructions that
;implicitly use the DS segment by default.
;mov AX,0xB800 ;// = 47104
;mov ES,AX
;screen output …
;for the screen, the messages in (“muo^n loa`i” ;(“muo^n loa`i va` pixel1 va` pixel2 va` … ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”)
screensetup: ; point ES to video memory
.setupvideosegment:
mov AX,0xB800 ;// = 47104
mov ES,AX
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
;jmp clearscreenpixels
ret ; return
; from http://staff.ustc.edu.cn/~xyfeng/research/cos/resources/machine/mem.htm:
;0x0000:0x0000 1024 bytes Interrupt Vector Table
;0x0040:0x0000 256 bytes BIOS Data Area
;0x0050:0x0000 ? Free memory
;0x07C0:0x0000 512 bytes Boot sector code
;0x07E0:0x0000 ? Free memory
;0xA000:0x0000 64 Kb Graphics Video Memory
;0xB000:0x0000 32 Kb Monochrome Text Video Memory
;0xB800:0x0000 32 Kb Color Text Video Memory
;0xC000:0x0000 256 Kb1 ROM Code Memory
;0xFFFF:0x0000 16 bytes More BIOS data
;Clearing the Background
;Clearing the background is rather trivial. The goal is to set all of the attribute bytes to the background color
;you wish to clear it to. The basic idea is to create a loop that will set every other byte, starting at the first
;attribute byte, to the background color we wish to clear to. We must also be sure to only clear all of the attributes that
;are used to represent the string. In other words, be sure not to go past the last attribute byte. The last attribute byte is
;found at 80 * 25 * 2 – 1. The 80 is the width and the 25 is the height. The 2 is there because two bytes make up each
;character; one for the character and one for the attribute. Finally the 1 is subtracted because our first attribute byte is
;actually the second byte at the beginning The 1 simply takes into account that we start our count at one instead of zero.
;The right most hex digit sets the lower four bits of the attribute byte. The lower four bits control the character color while the upper
;four bits (the left most hex digit) control the background color and flash bit. We set the background and flash bits (upper four bits) to 0h
; because 0h corresponds to the color black with no flashing.
;color index hex 64-color palette index
;Black 0 00h 0
;Blue 1 01h 1
;Green 2 02h 2
;Cyan 3 03h 3
;Red 4 04h 4
;Magenta 5 05h 5
;Brown 6 06h 20
;Light Gray 7 07h 7
;Dark Gray 8 08h 56
;Bright Blue 9 09h 57
;Bright Green 10 0Ah 58
;Bright Cyan 11 0Bh 59
;Bright Red 12 0Ch 60
;Bright Magenta 13 0Dh 61
;Bright Yellow 14 0Eh 62
;Bright White 15 0Fh 63
clearscreenpixels:
mov CX,80 * 25 * 2 – 1
mov BX,1
.Loopthroughscreenpixels:
cmp BX,CX
ja .finishclearscreenpixels ;CF = 0 and ZF = 0
;ja Loads EIP with the specified address, if first operand of previous CMP instruction is greater than the second. ja is the same as jg, except that it performs an unsigned comparison.
mov byte [ES:BX],70h ;Set background to light gray
;and the text to black
;with no flashing text
add BX,2
jmp .Loopthroughscreenpixels ; jmp Loads EIP with the specified address
.finishclearscreenpixels:
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
;jmp exit
;jmp sayhello
ret
sayhello:
mov byte [ES:0],’h’
mov byte [ES:2],’o’
mov byte [ES:4],’p’
mov byte [ES:6],’e’
mov byte [ES:8],’ ‘
mov byte [ES:10],’w’
mov byte [ES:12],’e’
mov byte [ES:14],’l’
mov byte [ES:16],’l’
; from NASM manual
; wordvar dw 123
; mov ax,[wordvar]
; mov ax,[wordvar+1]
; mov ax,[es:wordvar+bx]
; test stacksegment
; xor bl, bl
; from http://www.supernovah.com/Tutorials/Assembly4.php:
;When the processor pushes data onto the stack it does the following operations:
;1.Subtract 4 from SP or ESP
;2.Move the source data to the memory location [SS:SP] or [SS:ESP]
; push dword 117 ;Push the value 117 as a dword onto the stack
; push dword [0x500] ;Push the value at the memory location 0x500 onto the stack
; push byte ‘H’ ;Push the value 117 as a dword onto the stack ; nasm gives no error with the “byte” specification, see http://f.osdev.org/viewtopic.php?f=1&t=13399
; push byte ‘o’ ;Push the value 117 as a dword onto the stack
; push byte ‘p’ ;Push the value 117 as a dword onto the stack
; push byte ‘e’ ;Push the value 117 as a dword onto the stack
; push byte ‘W’ ;Push the value 117 as a dword onto the stack
; push byte ‘e’ ;Push the value 117 as a dword onto the stack
; push byte ‘l’ ;Push the value 117 as a dword onto the stack
; from http://www.supernovah.com/Tutorials/BootSector4.php:
; When the processor pushes data onto the stack it does the following operations:
;1.Subtract 4 from SP or ESP
;2.Move the source data to the memory location [SS:SP] or [SS:ESP]
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; mov [spprevious], SP
push ‘H ‘ ;Push the value 117 as a dword onto the stack
; mov [spnew], SP
; mov word [spcounter + 2 * 2], spprevious – spnew
push ‘O ‘ ;Push the value 117 as a dword onto the stack
push ‘P ‘ ;Push the value 117 as a dword onto the stack
push ‘E ‘ ;Push the value 117 as a dword onto the stack
push ‘W ‘ ;Push the value 117 as a dword onto the stack
push ‘E ‘ ;Push the value 117 as a dword onto the stack
push ‘L ‘ ;Push the value 117 as a dword onto the stack
;stacktop = stacksegment – datasegment + 64
; xor bl, bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 0] ; ‘l’
; mov byte [ES:30], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 1] ; ‘e’
; mov byte [ES:32], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 2] ; ‘W’
; mov byte [ES:34], bl
; mov byte bl, [0 + stacksegment – datasegment + 64 – 3] ; ‘e’
; mov byte [ES:36], bl
xor bl, bl
; STACK states at various points …
; *****************
; *****************
; *****************
; *****************
; ***************** << SP
; ***************** 2 bytes after call main
; *****************
; *****************
; *****************
; ***************** << SP
; ***************** + 2 bytes after call sayhello
; *****************
; ***************** 2 bytes after call main
; *****************
; ***************** << SP
; ***************** + 2 bytes after PUSH ‘H ‘
; *****************
; ***************** + 2 bytes after call sayhello
; *****************
; ***************** 2 bytes after call main
; *****************
; mov byte bl, [stacktop – 4 * 2 + 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
mov byte bl, [stacktop – 2 – 2 – 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:60], bl ; ‘H ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is reached
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:62], bl ; ‘O ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:64], bl ; ‘P ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:66], bl ; ‘E ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:68], bl ; ‘W ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:70], bl ; ‘E ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:72], bl ; ‘L ‘
mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2 – 2]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
;pop bx;
mov byte [ES:74], bl
; from http://stackoverflow.com/questions/15792702/convert-byte-to-string-in-x86-assembly-language
;.data
;mystr db 33 dup(0)
;
;.code
;
;EaxToBinaryString:
; mov ebx, offset mystr
; mov ecx, 32
;EaxToBinaryString1:
; mov dl, ‘0’ ; replace ‘0’ with 0 if you don’t want an ASCII string
; rol eax, 1
; adc dl, 0
; mov byte ptr [ebx], dl
; inc ebx
; loop EaxToBinaryString1
; ret
; from http://stackoverflow.com/questions/1922134/printing-out-a-number-in-assembly-language
; mov al,4
; or al,30h ;Important! =>Convert Character to Number!
; mov i,al
;
; MOV AH, 2 ;
; MOV DL, i ; Print Character.
; INT 21H ;
; mov [spprevious], SP
; … some operation …
; mov [spnew], SP
; mov word [spcounter + 2 * 0], spprevious – spnew
; xor bl, bl
; mov byte bl, [spcounter + 2 * 0]
; mov byte [ES:76], bl
; mov byte bl, [spcounter + 2 * 1]
; mov byte [ES:7], bl
; mov byte bl, [spcounter + 2 * 2]
; mov byte [ES:], bl
xor bl, bl
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘L ‘
;mov byte bl, [stacktop – 0]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
mov byte [ES:56], bl
;mov byte bl, [stacktop – 4]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘E ‘
mov byte [ES:54], bl
;mov byte bl, [stacktop – 8]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘W ‘
mov byte [ES:52], bl
;mov byte bl, [stacktop – 12]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘E ‘
mov byte [ES:46], bl
;mov byte bl, [stacktop – 16]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘P ‘
mov byte [ES:44], bl
;mov byte bl, [stacktop – 20]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘O ‘
mov byte [ES:42], bl
;mov byte bl, [stacktop – 24]
;pop byte bl; nasm gives error: invalid combination of opcode and operands
pop bx; ‘H ‘
mov byte [ES:40], bl
; test datasegment
xor bl, bl
mov byte bl, [datasegment]
; mov byte bl, [0]
; mov byte bl, [DS:0]
mov byte [ES:20], bl
mov byte bl, [datasegment + 1]
; mov byte bl, [1]
mov byte [ES:22], bl
mov byte bl, [datasegment + 2]
; mov byte bl, [2]
mov byte [ES:24], bl
mov byte bl, [datasegment + 3]
; mov byte bl, [3]
mov byte [ES:26], bl
mov byte bl, [datasegment + 4]
; mov byte bl, [4]
mov byte [ES:28], bl
mov byte bl, [datasegment + 5]
; mov byte bl, [5]
mov byte [ES:30], bl
mov byte bl, [datasegment + 6]
; mov byte bl, [6]
mov byte [ES:32], bl
mov byte bl, [datasegment + 7]
; mov byte bl, [7]
mov byte [ES:34], bl
; mov byte [ES:16], [datasegment + 1]
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
;jmp exit
ret
exit:
; to use the stack, use “call” and “ret” instead of “jmp”
; or just let the program flows, without the jmp, to instructions that follow
; jmp hang
hang:
jmp hang ; or, equivalently in nasm: jmp $
hlt ; halt the system
times 510-($-$$) db 0 ; 2 bytes less now; $ = beginning of current line/expression = “times”, $$ = beginning of current section = “hang:”
db 0x55
db 0xAA
;********************************************
;*** NOTE ***
; from arpaci dusseau http://pages.cs.wisc.edu/~remzi/OSTEP/vm-segmentation.pdf
;an idea was born, and it is called segmenta-
;tion. It is quite an old idea, going at least as far back as the very early
;1960’s [H61, G62]. The idea is simple: instead of having just one base
;and bounds pair in our MMU, why not have a base and bounds pair per
;logical segment of the address space?
;[G62] “Fact Segmentation”
;M. N. Greenfield
;Proceedings of the SJCC, Volume 21, May 1962
;Another early paper on segmentation; so early that it has no references to other work.
;[H61] “Program Organization and Record Keeping for Dynamic Storage”
;A. W. Holt
;Communications of the ACM, Volume 4, Issue 10, October 1961
;An incredibly early and difficult to read paper about segmentation and some of its uses.
; from http://en.wikipedia.org/wiki/THE_multiprogramming_system
; The THE multiprogramming system was a computer operating system designed by a team led by Edsger W. Dijkstra, described in monographs in 1965-66[1] and published in 1968.[2] Dijkstra never named the system; “THE” is simply the abbreviation of “Technische Hogeschool Eindhoven”, then the name (in Dutch) of the Eindhoven University of Technology of the Netherlands. The THE system was primarily a batch system[3] that supported multitasking; it was not designed as a multi-user operating system. It was much like the SDS 940, but “the set of processes in the THE system was static”.[3]
;The THE system apparently introduced the first forms of software-based memory segmentation (the Electrologica X8 did not support hardware-based memory management),[3] freeing programmers from being forced to use actual physical locations on the drum memory. It did this by using a modified ALGOL compiler (the only programming language supported by Dijkstra’s system) to “automatically generate calls to system routines, which made sure the requested information was in memory, swapping if necessary”.[3]
; from NASM manual:
;NASM gives special treatment to symbols beginning with a period. A label beginning with a single period is treated as a local label, which means that it is associated with the previous non-local label. So, for example:
;label1 ; some code
;.loop
; ; some more code
; jne .loop
; ret
;label2 ; some code
;.loop
; ; some more code
; jne .loop
; ret
;In the above code fragment, each JNE instruction jumps to the line immediately before it, because the two definitions of .loop are kept separate by virtue of each being associated with the previous non-local label.
;from http://wiki.osdev.org/Interrupts
; if IRQ 6 is sent to the PIC by a device, the PIC would tell the CPU to service INT 0Eh, which presumably has code for interacting with whatever device sent the interrupt in the first place. Of course, there can be trouble when two or more devices share an IRQ; if you wonder how this works, check out Plug and Play.
; from http://www.techmasala.com/2006/03/31/foundation-stone-3-bios-part-2-the-interrupt-vector-table/:
;Foundation stone #3 – BIOS part 2 – The interrupt vector table
;by Ramesh on Friday,March 31, 2006 @ 9:50 am
;In my post Foundation stone #2 we saw that BIOS is the one that takes in charge when you switch on your PC. After collecting the inventory of available and properly working hardware, the BIOS sets up what is called as the Interrupts area. An interrupt is a signal to the processor that there is something that needs its attention. As such each and every piece of hardware that is put together in your PC is useless unless it is orchestrated well. Take for example the keyboard, if the attention is not given at the right time when you press a key and reciprocated accordingly wherever you are then you can call the thing that is sitting in front of you as dumb
;So when the BIOS is done with the inventory of hardware, it initializes a memory space of 1024 bytes starting at 0000:0000h (this is a representation of memory location in the form of segment:offset in hexadecimal). An interrupt is a small routine or code that has the necessary details of the interrupt and occupies 4 bytes. So starting at memory location 0000:0000h interrupts are stored. So a total of 256 interrupts can be stored in a the allotted 1024 bytes but all is not being initialized by the BIOS. There are different types of interrupts, hardware interrupts, software interrupts, user interrupts and so on. The BIOS fills up the hardware interrupts and the software interrupts are mostly added by the OS.
;The Interrupt Vector Table (IVT) is a mapping of the interrupt number and the memory location in the form of segment:offset. This memory location contains the interrupt code for that particular interrupt. It is the responsibility of the OS to keep track of the IVT and monitor for interrupt and notify the processor. So what happens when you press a key or release a key, the keyboard send signals that contain information on what key was pressed or released. This gets stored in the memory location assigned for the keyboard interrupt (traditionally interrupt 09h is for keyboard). The OS which is constantly looking for these interrupts immediately captures the information and sends it for processing accordingly. The interrupt number and other details could differ from one BIOS manufacturer to other. You can get a lot of information about BIOS and interrupts from the BIOS central site.
; conventionally [c.f. http://en.wikipedia.org/wiki/Conventional_memory, http://en.wikipedia.org/wiki/Power-on_self-test%5D people agree upon the following memory map … from http://www.supernovah.com/Tutorials/Assembly2.php:
;Default Memory
;When the computer boots, the BIOS loads the memory with a lot of different data. This data resides in different places throughout memory and we are only left with 630Kb of memory to work with in the middle of everything. Here is a table showing the map of the memory directly after the computer boots:
;All ranges are inclusive
;Address Range (in hex) Size Type Description
;0 – 3FF 1Kb Ram Real Mode Interrupt Vector Table (IVT)
;400 – 4FF 256 bytes Ram BIOS Data Area (BDA)
;500 – 9FBFF 630Kb Ram Free Memory
;9FC00 – 9FFFF 1Kb Ram Extended BIOS Area (EBDA)
;A0000 – BFFFF 128Kb Video Ram VGA Frame Buffer
;C0000 – C7FFF 32Kb Rom Video Bios
;C8000 – EFFFF 160kb Rom Misc.
;F0000 – FFFFF 64Kb
; from NASM manual
;Multi-line macros are much more like the type of macro seen in MASM and TASM: a multi-line macro definition in NASM looks something like this.
;%macro prologue 1
; push ebp
; mov ebp,esp
; sub esp,%1
;%endmacro
; from http://www.husseinsspace.com/teaching/udw/1996/asmnotes/chaptwo.htm:
;The SHR/SLR instructions
;format:
;SHR destination,1
;SHR destination,CL
; SHL destination,1
; SHL destination,CL
;SHR shifts the destination right bitwise either 1 position or a number of positions determined by the current value of the CL register. SHL shifts the destination left bitwise either 1 position or a number of positions determined by the current value of the CL register. The vacant positions are filled by zeros.
;example:
;shr ax,1
; shl ax,1
;The first example effectively divides ax by 2 and the second example effectively multiplies ax by 2. These commands are faster than using DIV and MUL for arithmetic involving powers of 2.
;****************************
; from Intel Programmer’s Reference Manual
;10.1 Processor State After Reset
;The contents of EAX depend upon the results of the power-up self test. The self-test may be requested externally by assertion of BUSY# at the end of RESET. The EAX register holds zero if the 80386 passed the test. A nonzero value in EAX after self-test indicates that the particular 80386 unit is faulty. If the self-test is not requested, the contents of EAX after RESET is undefined.
;DX holds a component identifier and revision number after RESET as Figure 10-1 illustrates. DH contains 3, which indicates an 80386 component. DL contains a unique identifier of the revision level.
;Control register zero (CR0) contains the values shown in Figure 10-2 . The ET bit of CR0 is set if an 80387 is present in the configuration (according to the state of the ERROR# pin after RESET). If ET is reset, the configuration either contains an 80287 or does not contain a coprocessor. A software test is required to distinguish between these latter two possibilities.
;The remaining registers and flags are set as follows:
; EFLAGS =00000002H
; IP =0000FFF0H
; CS selector =000H
; DS selector =0000H
; ES selector =0000H
; SS selector =0000H
; FS selector =0000H
; GS selector =0000H
; IDTR:
; base =0
; limit =03FFH
;All registers not mentioned above are undefined.
;These settings imply that the processor begins in real-address mode with interrupts disabled.
;10.2 Software Initialization for Real-Address Mode
;In real-address mode a few structures must be initialized before a program can take advantage of all the features available in this mode.
;10.2.1 Stack
;No instructions that use the stack can be used until the stack-segment register (SS) has been loaded. SS must point to an area in RAM.
;10.2.2 Interrupt Table
;The initial state of the 80386 leaves interrupts disabled; however, the processor will still attempt to access the interrupt table if an exception or nonmaskable interrupt (NMI) occurs. Initialization software should take one of the following actions: Change the limit value in the IDTR to zero. This will cause a shutdown if an exception or nonmaskable interrupt occurs. (Refer to the 80386 Hardware Reference Manual to see how shutdown is signalled externally.)
; Put pointers to valid interrupt handlers in all positions of the interrupt table that might be used by exceptions or interrupts.
; Change the IDTR to point to a valid interrupt table.
;
;10.2.3 First Instructions
;After RESET, address lines A{31-20} are automatically asserted for instruction fetches. This fact, together with the initial values of CS:IP, causes instruction execution to begin at physical address FFFFFFF0H. Near (intrasegment) forms of control transfer instructions may be used to pass control to other addresses in the upper 64K bytes of the address space. The first far (intersegment) JMP or CALL instruction causes A{31-20} to drop low, and the 80386 continues executing instructions in the lower one megabyte of physical memory. This automatic assertion of address lines A{31-20} allows systems designers to use a ROM at the high end of the address space to initialize the system.
; from http://en.wikipedia.org/wiki/Interrupt_descriptor_table
;In the 8086 processor, the IDT resides at a fixed location in memory from address 0x0000 to 0x03ff, and consists of 256 four-byte real mode pointers (256 × 4 = 1024 bytes of memory). In the 80286 and later, the size and locations of the IDT can be changed in the same way as it is done in protected mode, though it does not change the format of it. A real mode pointer is defined as a 16-bit segment address and a 16-bit offset into that segment. A segment address is expanded internally by the processor to 20 bits thus limiting real mode interrupt handlers to the first 1 megabyte of addressable memory. The first 32 vectors are reserved for the processor’s internal exceptions, and hardware interrupts may be mapped to any of the vectors by way of a programmable interrupt controller.
; A commonly used x86 real mode interrupt is INT 10, the Video BIOS code to handle primitive screen drawing functions such as pixel drawing and changing the screen resolution.
; from http://software.intel.com/en-us/articles/introduction-to-x64-assembly
; XOR EAX, EAX ; zero out eax
; MOV ECX, 10 ; loop 10 times
;Label: ; this is a label in assembly
; INX EAX ; increment eax
; LOOP Label ; decrement ECX, loop if not 0
; from https://courses.engr.illinois.edu/ece390/books/artofasm/CH06/CH06-5.html#HEADING5-294
; mov ecx, 255
;ArrayLp: mov Array[ecx], cl
; loop ArrayLp
; mov Array[0], 0
;The last instruction is necessary because the loop does not repeat when cx is zero. Therefore, the last element of the array that this loop processes is Array[1], hence the last instruction.
; The loop instruction does not affect any flags.
; 2.17.2014 chu’ Ha^n telephoned about obtaining literature on American Philosophy and on US Census Data particularly
; US Census Data on black population expansion into US and into the world …
; following day: couple resembling co^ Be^ and David Lowe seen at Post Office when we tried to mail chu’ Kha’s preserved fruit to father in Michigan
; from http://randomascii.wordpress.com/2012/12/29/the-surprising-subtleties-of-zeroing-a-register/
; also see http://navet.ics.hawaii.edu/~casanova/courses/ics312_spring14/slides/ics312_bits_2.pdf
;Tabula rasa
;The x86 instruction set does not have a special purpose instruction for zeroing a register. An obvious way of dealing with this would be to move a constant zero into the register, like this:
;mov eax, 0
;That works, and it is fast. Benchmarking this will typically show that it has a latency of one Sandybridge diecycle the result can be used in a subsequent instruction on the next cycle. Benchmarking will also show that this has a throughput of three-per-cycle. The Sandybridge documentation says that this is the maximum integer throughput possible, and yet we can do better.
;Its too big
;The x86 instruction used to load a constant value such as zero into eax consists of a one-byte opcode (0xB8) and the constant to be loaded. The problem, in this scenario, is that eax is a 32-bit register, so the constant is 32-bits, so we end up with a five-byte instruction:
;B8 00 00 00 00 mov eax, 0
;Instruction size does not directly affect performance you can create lots of benchmarks that will prove that it is harmless but in most real programs the size of the code does have an effect on performance. The cost is extremely difficult to measure, but it appears that instruction-cache misses cost 10% or more of performance on many real programs. All else being equal, reducing instruction sizes will reduce i-cache misses, and therefore improve performance to some unknown degree.
;Smaller alternatives
;Many RISC architectures have a zero register in order to optimize this particular case, but x86 does not. The recommended alternative for years has been to use xor eax, eax. Any register exclusive ored with itself gives zero, and this instruction is just two bytes long:
;33 C0 xor eax, eax
;Careful micro-benchmarking will show that this instruction has the same one-cycle latency and three-per-cycle throughput of mov eax, 0 and it is 60% smaller (and recommended by Intel), so all is well.
;Suspicious minds
;If you really understand how CPUs work then you should be concerned with possible problems with using xor eax, eax to zero the eax register. One of the main limitations on CPU performance is data dependencies. While a Sandybridge processor can potentially execute three integer instructions on each cycle, in practice its performance tends to be lower because most instructions depend on the results of previous instructions, and are therefore serialized. The xor eax, eax instruction is at risk for such serialization because it uses eax as an input. Therefore it cannot (in theory) execute until the last instruction that wrote to eax completes. For example, consider this code fragment below:
;1: add eax, 1
;2: mov ebx, eax
;3: xor eax, eax
;4: add eax, ecx
;Careful micro-benchmarking will show that this instruction has the same one-cycle latency and three-per-cycle throughput of mov eax, 0 and it is 60% smaller (and recommended by Intel), so all is well.
;Ideally we would like our awesome out-of-order processor to execute instructions 1 and 3 in parallel. There is a literal data dependency between them, but a sufficiently advanced processor could detect that this dependency is artificial. The result of the xor instruction doesnt depend on the value of eax, it will always be zero.
;It turns out that for x86 processors have for years handled xor of a register with itself specially. Every out-of-order Intel and AMD processor that I am aware of can detect that there is not really a data dependency and it can execute instructions 1 and 3 in parallel. Which is great. The CPUs use register renaming to create a new eax for the sequence of instructions starting with instruction 3.
; from http://stackoverflow.com/questions/4909563/why-should-code-be-aligned-to-even-address-boundaries-on-x86
;Because the (16 bit) processor can fetch values from memory only at even addresses, due to its particular layout: it is divided in two “banks” of 1 byte each, so half of the data bus is connected to the first bank and the other half to the other bank. Now, suppose these banks are aligned (as in my picture), the processor can fetch values that are on the same “row”.
; bank 1 bank 2
;+——–+——–+
;| 8 bit | 8 bit |
;+——–+——–+
;| | |
;+——–+——–+
;| 4 | 5 | ;+——–+——–+
;| 2 | 3 |
;+——–+——–+
;| 0 | 1 |
;+——–+——–+
; \ / \ /
; | | | |
; | | | |
; data bus (to uP)
;Now, since this fetch limitation, if the cpu is forced to fetch values which are located on an odd address (suppose 3), it has to fetch values at 2 and 3, then values at 4 and 5, throw away values 2 and 5 then join 4 and 3 (you are talking about x86, which as a little endian memory layout).
; That’s why is better having code (and data!) on even addresses.
;PS: On 32 bit processors, code and data should be aligned on addresses which are divisible by 4 (since there are 4 banks).
;Hope I was clear. 🙂
;share|improve this answer
;answered Feb 5 ’11 at 23:02
;BlackBear
;9,42131746
;bio
;website google.it
;location Trento, Italy
;age 19
; from http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/
;Conclusion: On recent Intel processors, data alignment does not make processing measurably faster. Data alignment for speed is a myth.
;Acknowledgement: I am grateful to Owen Kaser for pointing me to the references on this issue.
;http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/
;\[ d E S F a s a d o \]
;11/9/99
;DOS: nasm -f bin -o your_file.com your_file.asm
;1)mov ax,your_segment
; mov ds,ax
;2) mov ax,[your_segment]
; mov ds,ax
;first of all you cant use mov ds,something… secondly you are trying to put
;in DS an offset of the current CS.
;The second example is what you have to do.
;hope this help..
;–
;[ yOu HaVe To SeArCh AnD sEaRcH, rElAtE iNfO, pRoBe AnD pRobE, tHeRe Is NoT
;aNoThEr WaY ]
;[ dOnT nEvEr gIvE uP, uSe YoR bRaIn At LeAsT aT 1o0% ]
;ASM CodER, PC HW & Electrical Technitian
;desf…@ciudad.com.ar
;http://members.xoom.com/desfasado >>> dENarixs OS Project
;UIN: 30796163
**********************************************************************************************************
testNASM.lst
1 ; boot.asm
2 ; bin version
3
4 ;from NASM manual:
5 ; The BITS directive specifies whether NASM should generate code designed to run on a processor operating in 16-bit mode, 32-bit mode or 64-bit mode.
6 ; You do not need to specify BITS 32 merely in order to use 32-bit instructions in a 16-bit DOS program; if you do, the assembler will generate incorrect code because it will be writing code targeted at a 32-bit pla
7 ; When NASM is in BITS 16 mode, instructions which use 32-bit data are prefixed with an 0x66 byte, and those referring to 32-bit addresses have an 0x67 prefix. In BITS 32 mode, the reverse is true: 32-bit instructio
8 ; When NASM is in BITS 64 mode, most instructions operate the same as they do for BITS 32 mode.
9 [BITS 16]
10
11 ; from the Programmer’s Reference Manual
12 ;The segment containing the currently executing sequence of instructions is known as the current code segment;
13 ;it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using
14 ;as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment
15 ;control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.
16 ;The instruction pointer register (EIP) contains the offset address, relative to the start of the current code
17 ;segment, of the next sequential instruction to be executed. The instruction pointer is not directly visible
18 ;to the programmer; it is controlled implicitly by control-transfer instructions, interrupts, and exceptions.
19 ;As Figure 2-9 shows, the low-order 16 bits of EIP is named IP and can be used by the processor as a unit.
20 ;This feature is useful when executing instructions designed for the 8086 and 80286 processors.
21
22
23 ; from http://www.supernovah.com/Tutorials/BootSector2.php
24 ;As stated earlier, we cannot be sure if the BIOS set us up with the starting address of 0x7C0:0x0 or 0x0:0x7C00.
25 ;We will use the second segment offset pair to execute our boot sector so we know for sure how the CPU will access
26 ;our code. To do this, our very first instruction will be a far jump that simply jumps to the next instruction.
27 ;The trick is, if we specify a segment, even if it is 0x0, the jmp will be a far jump and the CS register will be
28 ;loaded with the value 0x0 and the IP register will be loaded with the address of the next instruction to be
29 ;executed.
30 ;[BITS 16]
31 ;[ORG 0x7C00]
32 ;jmp 0x0:Start
33 ;Start:
34 ; This code will set the CS segment to 0x0, set the IP register to the the very next instruction which will be slightly past 0x7C00, ….
35
36 ; universal-loop
37 ; {
38 ; start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // in “gia ba?o”, “ba?o” ~ maintain as in “ba?o thu?/to^`n” …
39 ; try/if ;// tin messages …. the try/if is the “gia” of “gia ba?o” …
40 ; maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i va` messageA va` messageB va` messageNEW va` tinLA`NH va`… ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”); // the message “stack” is loaded or p
41 ; ;catch/else ;// unmaintainable tin/messages or kho’ tin hay kho^ng tin no messages … SBTN Uye^n Thi. commercial for MBR [master boot record] “kho’ tin nhu+ng co’ tha^.t …”
42 ; ; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
43 ; go-to-jump-tro+?-ve^` start-ORG-nguye^n-thu?y: maintain-gi`n-giu+~-ba?o-to^`n (“muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”);
44 ; }
45
46 ; irish-catholic Pat Benatar song “heartbreaker, dreammaker, don’t you mess around with me …” ….
47 ; perhaps “there’s beggary in a love that can be reckoned” when love is unconditional–gia ba?o chu’ hoa`ng to^n an hoa`ng phi hu`ng and 10 commandments–but
48 ; the ten commandments say there’s a love that’s conditional … and the 10 commandments describe the limits or conditions of that love …
49 ; from http://wiki.osdev.org/Babystep2:
50 ;some say that the bootloader is loaded at [metaphorical address] 0000:7C00, while others say 07C0:0000.
51 ;This is in fact the same [real] address: 16 * 0x0000 + 0x7C00 = 16 * 0x07C0 + 0x0000 = 0x7C00.
52
53 ;%define ORIGIN ; ….. comment this out to use “org 0” instead of “org 0x07C0” …
54
55 %ifdef ORIGIN
56 [ORG 0x7c00]
57 ;segment .text align=16
58 ; segment:offset … ds:offset or cs:offset … 0:offset-from-0x7COO … that is, labels in code following is addressed as 0:0x7C00+offset-from-start-of-file
59 ;Following code will set the CS segment to 0x0, set the IP register to the the very next instruction which will be slightly past 0x7C00, ….
60 jmp 0x0:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
61 ; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
62
63 %else ;
64 [ORG 0]
65 ;segment .text align=16
66 ; segment:offset … ds:offset or cs:offset … 0x07C0:offset-from-0 … that is, labels in the code following is addressed as 0x07C0:0+offset-from-start-of-file
67 ;Following code will set the CS segment to 0x07C0, set the IP register to the the very next instruction which will be slightly past 0x0, ….
68 00000000 EA[6600]C007 jmp 0x07C0:start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
69 ; jmp start ; set up the ip stack pointer and cs segment register implicitly via jmp instruction
70
71 %endif ; ORIGIN
72
73 %ifdef ORIGIN
74 %define MEMORYSEGMENTREALLOWBOUND 0x7C00
75 %else
76 %define MEMORYSEGMENTREALLOWBOUND 0x0000
77 %endif ; ORIGIN
78 %define SEGMENTSIZE 512
79 %define MEMORYSEGMENTREALUPPERBOUND MEMORYSEGMENTREALLOWBOUND + SEGMENTSIZE
80
81 ; data segment
82 ; section .data
83 ;section datasegment align=16 ; start= follows=
84 ;segment datasegment align=16 ; start= follows=
85 ; align 16
86 ;segment .data align=16
87 ;datasegment dw 123
88 00000005 486F70652057656C6C datasegment db ‘Hope Well’
89
90 ; stack segment
91 ; section .bss
92 ; section stacksegment align=16 ; start= follows=
93 ; segment stacksegment align=16 ; start= follows=
94 ; align 16
95 ;segment .stack align=16
96 0000000E stacksegment resb 64
97 ****************** warning: uninitialized space declared in .text section: zeroing
98 stacktop:
99
100 0000004E 0000 spprevious dw 0
101 00000050 0000 spnew dw 0
102 00000052 0000 spcounter times 10 dw 0
103
104 ; from NASM manual
105 ;message db ‘hello, world’
106 ;msglen equ $-message
107
108 ;stacktop = stacksegment – datasegment + 64
109
110 ;segment .text align=16
111 ; set up the data, stack, etc. segment registers
112 ;segment .text align=16
113 start:
114 ;mov AX, 0x0
115 ;mov AX,seg DATASEGMENT1
116 ;; mov AX, datasegment
117 ;; mov AX, seg datasegment ; error: binary output format does not support segment base references
118 ;; mov AX, [datasegment]
119 %ifdef ORIGIN
120 mov AX, 0x0
121 ; mov AX, 0x0 + datasegment
122 mov DS,AX
123 ; from http://www.supernovah.com/Tutorials/BootSector2.php
124 ; The processor uses the SS:SP segment offset address to determine the location of the stack.
125 ; from http://wiki.osdev.org/Stack:
126 ;Take care when implementing your kernel. If you use segmentation, the DS segment should be configured to have it’s base at the same address as SS does. Otherwise you may run into problems when passing pointers to l
127 ;mov AX,seg STACKSEGMENT
128 ;mov AX, 0x0 + stacksegment
129 mov AX, 0x0
130 mov SS,AX
131 mov SP, 0x0 + stacktop
132 %else
133 ; mov AX, 0x07C0 + datasegment
134 ; mov AX, datasegment
135 00000066 B8C007 mov AX, 0x07C0
136 00000069 8ED8 mov DS,AX
137 ; from http://www.supernovah.com/Tutorials/BootSector2.php
138 ; The processor uses the SS:SP segment offset address to determine the location of the stack.
139 ; from http://wiki.osdev.org/Stack:
140 ;Take care when implementing your kernel. If you use segmentation, the DS segment should be configured to have it’s base at the same address as SS does. Otherwise you may run into problems when passing pointers to l
141 ;mov AX,seg STACKSEGMENT
142 ; mov AX, 0x07C0 + stacksegment
143 ;mov AX, stacksegment
144 0000006B B8C007 mov AX, 0x07C0
145 0000006E 8ED0 mov SS,AX
146 ; mov SP, 0x07C0 + stacktop
147 00000070 BC[4E00] mov SP, stacktop
148 ; from http://frz.ir/dl/tuts/8086_Assembly.pdf
149 ;MOV REG, memory
150 ;MOV memory, REG
151 ;MOV REG, REG
152 ;MOV memory, immediate
153 ;MOV REG, immediate
154 ;REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.
155 ;memory: [BX], [BX+SI+7], variable, etc…
156 ;immediate: 5, -24, 3Fh, 10001101b, etc…
157 ; mov CX, SP
158 ; mov [spprevious], SP
159 ; … some operation …
160 ; mov [spnew], SP
161 ; mov word [spcounter], spprevious – spnew
162 %endif ; ORIGIN
163 ;mov AX,seg STACKSEGMENT
164 ; mov AX, stacksegment
165 ; mov SS,AX
166 ; mov SP,stacktop
167
168 ; to use the stack, use “call” and “ret” instead of “jmp”
169 ; effectively, the illegal “mov eip, label” ~ legal “jmp label”
170 ; or just let the program flows, without the jmp, to instructions that follow
171 ; jmp main ; jmp Loads EIP with the specified address
172
173 ; PUSH instruction from programmer’s reference manual
174 ;IF StackAddrSize = 16
175 ;THEN
176 ; IF OperandSize = 16 THEN
177 ; SP := SP – 2;
178 ; (SS:SP) := (SOURCE); (* word assignment *)
179 ; ELSE
180 ; SP := SP – 4;
181 ; (SS:SP) := (SOURCE); (* dword assignment *)
182 ; FI;
183 ;ELSE (* StackAddrSize = 32 *)
184 ; IF OperandSize = 16
185 ; THEN
186 ; ESP := ESP – 2;
187 ; (SS:ESP) := (SOURCE); (* word assignment *)
188 ; ELSE
189 ; ESP := ESP – 4;
190 ; (SS:ESP) := (SOURCE); (* dword assignment *)
191 ; FI;
192 ;FI;
193 ; RET instruction
194 ;IF instruction = near RET
195 ;THEN;
196 ; IF OperandSize = 16
197 ; THEN
198 ; IP := Pop();
199 ; EIP := EIP AND 0000FFFFH;
200 ; ELSE (* OperandSize = 32 *)
201 ; EIP := Pop();
202 ; FI;
203 ; IF instruction has immediate operand THEN eSP := eSP + imm16; FI;
204 ;FI
205 ; CALL instruction
206 ;IF rel16 or rel32 type of call
207 ;THEN (* near relative call *)
208 ; IF OperandSize = 16
209 ; THEN
210 ; Push(IP);
211 ; EIP := (EIP + rel16) AND 0000FFFFH;
212 ; ELSE (* OperandSize = 32 *)
213 ; Push(EIP);
214 ; EIP := EIP + rel32;
215 ; FI;
216 ;FI;
217
218
219
220 ; mov [spprevious], SP
221 ; … some operation …
222 ; mov [spnew], SP
223 ; mov word [spcounter + 2 * 0], spprevious – spnew
224
225 ; mov [spprevious], SP
226 00000073 E80000 call main ; call = push + jmp; ret = pop + jmp
227 ; mov [spnew], SP
228 ; mov word [spcounter + 2 * 0], spprevious – spnew
229
230 ; from http://wiki.osdev.org/Babystep2:
231 ; In real mode, addresses are calculated as segment * 16 + offset. Since offset can be much larger than 16, there are many pairs
232 ; of segment and offset that point to the same address.
233 %define REALADDRESS(SEGMENTNO,OFFSETNO) SEGMENTNO*16+OFFSETNO
234
235 %define VERIFYSEGMENTADDRESSBOUND(SEGMENTADDRESSTOVERIFY, OFFSETADDRESSTOVERIFY) (REALADDRESS(SEGMENTADDRESSTOVERIFY,OFFSETADDRESSTOVERIFY) > MEMORYSEGMENTREALLOWBOUND) & (REALADDRESS(SEGMENTADDRESSTOVERIFY,OFFSET
236 ; generate some virtual segment:offset address for use with a real address …
237 ; TO DO: align the generated addresses to “natural” byte boundaries …
238 ; %define GENERATESEGMENTADDRESS(REALADDRESSNO, &GENSEGMENTNO, &GENOFFSETNO) …………….
239 ; %define GENERATEVIRTUALSEGMENTADDRESS(REALADDRESSNO, VIRTUALOFFSETADDRESSINPUT) (REALADDRESSNO – VIRTUALOFFSETADDRESSINPUT)/16
240 ; %define GENERATEOFFSETNO(REALADDRESSNO, VIRTUALSEGMENTADDRESSINPUT) (REALADDRESSNO – VIRTUALSEGMENTADDRESSINPUT * 16)
241
242 ; from http://geezer.osdevbrasil.net/johnfine/segments.htm:
243 ;The way it really works
244 ; Each segment register is really four registers: A selector register
245 ;A base register
246 ;A limit register
247 ;An attribute register
248 ;
249 ;In all modes, every access to memory that uses a segment register uses the base, limit, and attribute portions of the segment register and does not use the selector portion.
250 ;Every direct access to a segment register (PUSHing it on the stack, MOVing it to a general register etc.) uses only the selector portion. The base, limit, and attribute portions are either very hard or impossible t
251 ;Intel documentation refers to the hidden part of the segment register as a “descriptor cache”. This name obscures the actual behavior of the “hidden” part.
252 ; In real mode (or V86 mode), when you write any 16-bit value to a segment register, the value you write goes into the selector and 16 times that value goes into the base. The limit and attribute are not changed.
253 ;In pmode, any write to a segment register causes a descriptor to be fetched from the GDT or LDT and unpacked into the base, limit and attribute portion of the segment register. (Special exception for the NULL Selec
254 ;When the CPU switchs between real mode and pmode, the segment registers do not automatically change. The selectors still contain the exact bit pattern that was loaded into them in the previous mode. The hidden part
255
256 ;Writes to a segment register
257 ;When I refer to “writing to a segment register”, I mean any action that puts a 16-bit value into a segment register.
258 ;The obvious example is something like:
259 ; MOV DS,AX
260 ;However the same rules apply to many other situations, including: POP to a segment register.
261 ;FAR JMP or CALL puts a value in CS.
262 ;IRET or FAR RET puts a value in CS.
263 ;Both hardware and software interrupts put a value in CS.
264 ;A ring transition puts a value in both SS and CS.
265 ;A task switch loads all the segment registers from a TSS.
266
267 ; from the Programmer’s Reference Manual
268 ;The segment containing the currently executing sequence of instructions is known as the current code segment;
269 ;it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using
270 ;as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment
271 ;control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.
272
273 main:
274 ; to use the stack, use “call” and “ret” instead of “jmp”
275 ;jmp screensetup ; or just let the program flows, without the jmp, to instructions that follow
276
277 00000076 E80D00 call screensetup
278 00000079 E81000 call clearscreenpixels
279
280 ; mov [spprevious], SP
281 ; … some operation …
282 ; mov [spnew], SP
283 ; mov word [spcounter + 2 * 0], spprevious – spnew
284 ; mov [spprevious], SP
285 0000007C E82100 call sayhello
286 ; mov [spnew], SP
287 ; mov word [spcounter + 2 * 1], spprevious – spnew
288
289 0000007F E82A01 call exit
290 00000082 E82701 call hang
291 00000085 C3 ret ; return
292
293 ; from http://www.supernovah.com/Tutorials/BootSector4.php:
294 ;Video Memory
295 ;As previously stated, what is printed to the screen is simply controlled by a special section of memory called
296 ;the video memory (or VGA memory). This section of memory is then periodically copied to the video device
297 ;memory which is then presented to the screen by the Digital Analog Converter (DAC). Currently we are in text
298 ;mode 03h which is a form of EGA. The video memory for text mode 3h begins at 0xB8000. Text mode 03h is 80 characters wide
299 ;and 25 characters tall. This gives us 2000 total characters (80 * 25). Each character consists of 2 bytes which
300 ;yields 4000 bytes of memory in total. So this means that text mode 03h stores it’s video information (the information that is
301 ;printed to the screen) at the memory address 0xB8000 and it takes up 4000 bytes of memory.
302 ;Printing Character to the Screen
303 ;The first we must do in order to print character to the screen is to get a segment register setup that points
304 ;to the memory location 0xB8000 [= 753664 = 47104 * 16]. Remember that segments in real mode have the lower four bits implicitly
305 ;set to zero and because each hex digit represents four bits we can easily drop the right most zero on the
306 ;memory address when storing it in a segment register. We will use the ES segment register because we
307 ;still want to access our data with the DS segment so we don’t run into problems when using instructions that
308 ;implicitly use the DS segment by default.
309 ;mov AX,0xB800 ;// = 47104
310 ;mov ES,AX
311
312 ;screen output …
313 ;for the screen, the messages in (“muo^n loa`i” 314 ;(“muo^n loa`i va` pixel1 va` pixel2 va` … ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well”)
315
316 screensetup: ; point ES to video memory
317 .setupvideosegment:
318 00000086 B800B8 mov AX,0xB800 ;// = 47104
319 00000089 8EC0 mov ES,AX
320 ; to use the stack, use “call” and “ret” instead of “jmp”
321 ; or just let the program flows, without the jmp, to instructions that follow
322 ;jmp clearscreenpixels
323 0000008B C3 ret ; return
324
325 ; from http://staff.ustc.edu.cn/~xyfeng/research/cos/resources/machine/mem.htm:
326 ;0x0000:0x0000 1024 bytes Interrupt Vector Table
327 ;0x0040:0x0000 256 bytes BIOS Data Area
328 ;0x0050:0x0000 ? Free memory
329 ;0x07C0:0x0000 512 bytes Boot sector code
330 ;0x07E0:0x0000 ? Free memory
331 ;0xA000:0x0000 64 Kb Graphics Video Memory
332 ;0xB000:0x0000 32 Kb Monochrome Text Video Memory
333 ;0xB800:0x0000 32 Kb Color Text Video Memory
334 ;0xC000:0x0000 256 Kb1 ROM Code Memory
335 ;0xFFFF:0x0000 16 bytes More BIOS data
336
337
338 ;Clearing the Background
339 ;Clearing the background is rather trivial. The goal is to set all of the attribute bytes to the background color
340 ;you wish to clear it to. The basic idea is to create a loop that will set every other byte, starting at the first
341 ;attribute byte, to the background color we wish to clear to. We must also be sure to only clear all of the attributes that
342 ;are used to represent the string. In other words, be sure not to go past the last attribute byte. The last attribute byte is
343 ;found at 80 * 25 * 2 – 1. The 80 is the width and the 25 is the height. The 2 is there because two bytes make up each
344 ;character; one for the character and one for the attribute. Finally the 1 is subtracted because our first attribute byte is
345 ;actually the second byte at the beginning The 1 simply takes into account that we start our count at one instead of zero.
346
347 ;The right most hex digit sets the lower four bits of the attribute byte. The lower four bits control the character color while the upper
348 ;four bits (the left most hex digit) control the background color and flash bit. We set the background and flash bits (upper four bits) to 0h
349 ; because 0h corresponds to the color black with no flashing.
350
351 ;color index hex 64-color palette index
352 ;Black 0 00h 0
353 ;Blue 1 01h 1
354 ;Green 2 02h 2
355 ;Cyan 3 03h 3
356 ;Red 4 04h 4
357 ;Magenta 5 05h 5
358 ;Brown 6 06h 20
359 ;Light Gray 7 07h 7
360 ;Dark Gray 8 08h 56
361 ;Bright Blue 9 09h 57
362 ;Bright Green 10 0Ah 58
363 ;Bright Cyan 11 0Bh 59
364 ;Bright Red 12 0Ch 60
365 ;Bright Magenta 13 0Dh 61
366 ;Bright Yellow 14 0Eh 62
367 ;Bright White 15 0Fh 63
368
369
370
371 clearscreenpixels:
372 0000008C B99F0F mov CX,80 * 25 * 2 – 1
373 0000008F BB0100 mov BX,1
374 .Loopthroughscreenpixels:
375 00000092 39CB cmp BX,CX
376 00000094 7709 ja .finishclearscreenpixels ;CF = 0 and ZF = 0
377 ;ja Loads EIP with the specified address, if first operand of previous CMP instruction is greater than the second. ja is the same as jg, except that it performs an unsigned comparison.
378
379 00000096 26C60770 mov byte [ES:BX],70h ;Set background to light gray
380 ;and the text to black
381 ;with no flashing text
382 0000009A 83C302 add BX,2
383 0000009D EBF3 jmp .Loopthroughscreenpixels ; jmp Loads EIP with the specified address
384
385 .finishclearscreenpixels:
386 ; to use the stack, use “call” and “ret” instead of “jmp”
387 ; or just let the program flows, without the jmp, to instructions that follow
388 ;jmp exit
389 ;jmp sayhello
390 0000009F C3 ret
391
392 sayhello:
393 000000A0 26C606000068 mov byte [ES:0],’h’
394 000000A6 26C60602006F mov byte [ES:2],’o’
395 000000AC 26C606040070 mov byte [ES:4],’p’
396 000000B2 26C606060065 mov byte [ES:6],’e’
397 000000B8 26C606080020 mov byte [ES:8],’ ‘
398 000000BE 26C6060A0077 mov byte [ES:10],’w’
399 000000C4 26C6060C0065 mov byte [ES:12],’e’
400 000000CA 26C6060E006C mov byte [ES:14],’l’
401 000000D0 26C60610006C mov byte [ES:16],’l’
402 ; from NASM manual
403 ; wordvar dw 123
404 ; mov ax,[wordvar]
405 ; mov ax,[wordvar+1]
406 ; mov ax,[es:wordvar+bx]
407 ; test stacksegment
408 ; xor bl, bl
409 ; from http://www.supernovah.com/Tutorials/Assembly4.php:
410 ;When the processor pushes data onto the stack it does the following operations:
411 ;1.Subtract 4 from SP or ESP
412 ;2.Move the source data to the memory location [SS:SP] or [SS:ESP]
413 ; push dword 117 ;Push the value 117 as a dword onto the stack
414 ; push dword [0x500] ;Push the value at the memory location 0x500 onto the stack
415 ; push byte ‘H’ ;Push the value 117 as a dword onto the stack ; nasm gives no error with the “byte” specification, see http://f.osdev.org/viewtopic.php?f=1&t=13399
416 ; push byte ‘o’ ;Push the value 117 as a dword onto the stack
417 ; push byte ‘p’ ;Push the value 117 as a dword onto the stack
418 ; push byte ‘e’ ;Push the value 117 as a dword onto the stack
419 ; push byte ‘W’ ;Push the value 117 as a dword onto the stack
420 ; push byte ‘e’ ;Push the value 117 as a dword onto the stack
421 ; push byte ‘l’ ;Push the value 117 as a dword onto the stack
422 ; from http://www.supernovah.com/Tutorials/BootSector4.php:
423 ; When the processor pushes data onto the stack it does the following operations:
424 ;1.Subtract 4 from SP or ESP
425 ;2.Move the source data to the memory location [SS:SP] or [SS:ESP]
426
427 ; mov [spprevious], SP
428 ; … some operation …
429 ; mov [spnew], SP
430 ; mov word [spcounter + 2 * 0], spprevious – spnew
431
432 ; mov [spprevious], SP
433 000000D6 684820 push ‘H ‘ ;Push the value 117 as a dword onto the stack
434 ; mov [spnew], SP
435 ; mov word [spcounter + 2 * 2], spprevious – spnew
436
437 000000D9 684F20 push ‘O ‘ ;Push the value 117 as a dword onto the stack
438 000000DC 685020 push ‘P ‘ ;Push the value 117 as a dword onto the stack
439 000000DF 684520 push ‘E ‘ ;Push the value 117 as a dword onto the stack
440 000000E2 685720 push ‘W ‘ ;Push the value 117 as a dword onto the stack
441 000000E5 684520 push ‘E ‘ ;Push the value 117 as a dword onto the stack
442 000000E8 684C20 push ‘L ‘ ;Push the value 117 as a dword onto the stack
443 ;stacktop = stacksegment – datasegment + 64
444 ; xor bl, bl
445 ; mov byte bl, [0 + stacksegment – datasegment + 64 – 0] ; ‘l’
446 ; mov byte [ES:30], bl
447 ; mov byte bl, [0 + stacksegment – datasegment + 64 – 1] ; ‘e’
448 ; mov byte [ES:32], bl
449 ; mov byte bl, [0 + stacksegment – datasegment + 64 – 2] ; ‘W’
450 ; mov byte [ES:34], bl
451 ; mov byte bl, [0 + stacksegment – datasegment + 64 – 3] ; ‘e’
452 ; mov byte [ES:36], bl
453 000000EB 30DB xor bl, bl
454
455 ; STACK states at various points …
456 ; *****************
457 ; *****************
458 ; *****************
459 ; *****************
460 ; ***************** << SP
461 ; ***************** 2 bytes after call main
462 ; *****************
463
464 ; *****************
465 ; *****************
466 ; ***************** << SP
467 ; ***************** + 2 bytes after call sayhello
468 ; *****************
469 ; ***************** 2 bytes after call main
470 ; *****************
471
472 ; ***************** << SP
473 ; ***************** + 2 bytes after PUSH ‘H ‘
474 ; *****************
475 ; ***************** + 2 bytes after call sayhello
476 ; *****************
477 ; ***************** 2 bytes after call main
478 ; *****************
479
480 ; mov byte bl, [stacktop – 4 * 2 + 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point i
481 000000ED 8A1E[4800] mov byte bl, [stacktop – 2 – 2 – 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this point is
482 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
483 ;pop bx;
484 000000F1 26881E3C00 mov byte [ES:60], bl ; ‘H ‘
485 000000F6 8A1E[4600] mov byte bl, [stacktop – 2 * 2 – 2 – 2] ; four routines were called: call main, call screensetup, call clearscreenpixels, call sayhello of which only two routines were left opened on the stack by the time this poin
486 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
487 ;pop bx;
488 000000FA 26881E3E00 mov byte [ES:62], bl ; ‘O ‘
489 000000FF 8A1E[4400] mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2]
490 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
491 ;pop bx;
492 00000103 26881E4000 mov byte [ES:64], bl ; ‘P ‘
493 00000108 8A1E[4200] mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2]
494 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
495 ;pop bx;
496 0000010C 26881E4200 mov byte [ES:66], bl ; ‘E ‘
497 00000111 8A1E[4000] mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2]
498 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
499 ;pop bx;
500 00000115 26881E4400 mov byte [ES:68], bl ; ‘W ‘
501 0000011A 8A1E[3E00] mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2]
502 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
503 ;pop bx;
504 0000011E 26881E4600 mov byte [ES:70], bl ; ‘E ‘
505 00000123 8A1E[3C00] mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2 – 2]
506 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
507 ;pop bx;
508 00000127 26881E4800 mov byte [ES:72], bl ; ‘L ‘
509 0000012C 8A1E[3C00] mov byte bl, [stacktop – 2 * 2 – 2 – 2 – 2 – 2 – 2 – 2 – 2]
510 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
511 ;pop bx;
512 00000130 26881E4A00 mov byte [ES:74], bl
513
514 ; from http://stackoverflow.com/questions/15792702/convert-byte-to-string-in-x86-assembly-language
515 ;.data
516 ;mystr db 33 dup(0)
517 ;
518 ;.code
519 ;
520 ;EaxToBinaryString:
521 ; mov ebx, offset mystr
522 ; mov ecx, 32
523 ;EaxToBinaryString1:
524 ; mov dl, ‘0’ ; replace ‘0’ with 0 if you don’t want an ASCII string
525 ; rol eax, 1
526 ; adc dl, 0
527 ; mov byte ptr [ebx], dl
528 ; inc ebx
529 ; loop EaxToBinaryString1
530 ; ret
531 ; from http://stackoverflow.com/questions/1922134/printing-out-a-number-in-assembly-language
532 ; mov al,4
533 ; or al,30h ;Important! =>Convert Character to Number!
534 ; mov i,al
535 ;
536 ; MOV AH, 2 ;
537 ; MOV DL, i ; Print Character.
538 ; INT 21H ;
539
540
541 ; mov [spprevious], SP
542 ; … some operation …
543 ; mov [spnew], SP
544 ; mov word [spcounter + 2 * 0], spprevious – spnew
545 ; xor bl, bl
546 ; mov byte bl, [spcounter + 2 * 0]
547 ; mov byte [ES:76], bl
548 ; mov byte bl, [spcounter + 2 * 1]
549 ; mov byte [ES:7], bl
550 ; mov byte bl, [spcounter + 2 * 2]
551 ; mov byte [ES:], bl
552
553
554 00000135 30DB xor bl, bl
555 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
556 00000137 5B pop bx; ‘L ‘
557 ;mov byte bl, [stacktop – 0]
558 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
559 00000138 26881E3800 mov byte [ES:56], bl
560 ;mov byte bl, [stacktop – 4]
561 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
562 0000013D 5B pop bx; ‘E ‘
563 0000013E 26881E3600 mov byte [ES:54], bl
564 ;mov byte bl, [stacktop – 8]
565 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
566 00000143 5B pop bx; ‘W ‘
567 00000144 26881E3400 mov byte [ES:52], bl
568 ;mov byte bl, [stacktop – 12]
569 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
570 00000149 5B pop bx; ‘E ‘
571 0000014A 26881E2E00 mov byte [ES:46], bl
572 ;mov byte bl, [stacktop – 16]
573 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
574 0000014F 5B pop bx; ‘P ‘
575 00000150 26881E2C00 mov byte [ES:44], bl
576 ;mov byte bl, [stacktop – 20]
577 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
578 00000155 5B pop bx; ‘O ‘
579 00000156 26881E2A00 mov byte [ES:42], bl
580 ;mov byte bl, [stacktop – 24]
581 ;pop byte bl; nasm gives error: invalid combination of opcode and operands
582 0000015B 5B pop bx; ‘H ‘
583 0000015C 26881E2800 mov byte [ES:40], bl
584
585 ; test datasegment
586 00000161 30DB xor bl, bl
587 00000163 8A1E[0500] mov byte bl, [datasegment]
588 ; mov byte bl, [0]
589 ; mov byte bl, [DS:0]
590 00000167 26881E1400 mov byte [ES:20], bl
591 0000016C 8A1E[0600] mov byte bl, [datasegment + 1]
592 ; mov byte bl, [1]
593 00000170 26881E1600 mov byte [ES:22], bl
594 00000175 8A1E[0700] mov byte bl, [datasegment + 2]
595 ; mov byte bl, [2]
596 00000179 26881E1800 mov byte [ES:24], bl
597 0000017E 8A1E[0800] mov byte bl, [datasegment + 3]
598 ; mov byte bl, [3]
599 00000182 26881E1A00 mov byte [ES:26], bl
600 00000187 8A1E[0900] mov byte bl, [datasegment + 4]
601 ; mov byte bl, [4]
602 0000018B 26881E1C00 mov byte [ES:28], bl
603 00000190 8A1E[0A00] mov byte bl, [datasegment + 5]
604 ; mov byte bl, [5]
605 00000194 26881E1E00 mov byte [ES:30], bl
606 00000199 8A1E[0B00] mov byte bl, [datasegment + 6]
607 ; mov byte bl, [6]
608 0000019D 26881E2000 mov byte [ES:32], bl
609 000001A2 8A1E[0C00] mov byte bl, [datasegment + 7]
610 ; mov byte bl, [7]
611 000001A6 26881E2200 mov byte [ES:34], bl
612 ; mov byte [ES:16], [datasegment + 1]
613
614 ; to use the stack, use “call” and “ret” instead of “jmp”
615 ; or just let the program flows, without the jmp, to instructions that follow
616 ;jmp exit
617 000001AB C3 ret
618
619
620
621 exit:
622 ; to use the stack, use “call” and “ret” instead of “jmp”
623 ; or just let the program flows, without the jmp, to instructions that follow
624 ; jmp hang
625
626 hang:
627 000001AC EBFE jmp hang ; or, equivalently in nasm: jmp $
628 000001AE F4 hlt ; halt the system
629
630 000001AF 00 times 510-($-$$) db 0 ; 2 bytes less now; $ = beginning of current line/expression = “times”, $$ = beginning of current section = “hang:”
631 000001FE 55 db 0x55
632 000001FF AA db 0xAA
633 ;********************************************
634 ;*** NOTE ***
635 ; from arpaci dusseau http://pages.cs.wisc.edu/~remzi/OSTEP/vm-segmentation.pdf
636 ;an idea was born, and it is called segmenta-
637 ;tion. It is quite an old idea, going at least as far back as the very early
638 ;1960’s [H61, G62]. The idea is simple: instead of having just one base
639 ;and bounds pair in our MMU, why not have a base and bounds pair per
640 ;logical segment of the address space?
641 ;[G62] “Fact Segmentation”
642 ;M. N. Greenfield
643 ;Proceedings of the SJCC, Volume 21, May 1962
644 ;Another early paper on segmentation; so early that it has no references to other work.
645 ;[H61] “Program Organization and Record Keeping for Dynamic Storage”
646 ;A. W. Holt
647 ;Communications of the ACM, Volume 4, Issue 10, October 1961
648 ;An incredibly early and difficult to read paper about segmentation and some of its uses.
649
650 ; from http://en.wikipedia.org/wiki/THE_multiprogramming_system
651 ; The THE multiprogramming system was a computer operating system designed by a team led by Edsger W. Dijkstra, described in monographs in 1965-66[1] and published in 1968.[2] Dijkstra never named the system; “THE”
652 ;The THE system apparently introduced the first forms of software-based memory segmentation (the Electrologica X8 did not support hardware-based memory management),[3] freeing programmers from being forced to use ac
653
654
655 ; from NASM manual:
656 ;NASM gives special treatment to symbols beginning with a period. A label beginning with a single period is treated as a local label, which means that it is associated with the previous non-local label. So, for exam
657 ;label1 ; some code
658 ;.loop
659 ; ; some more code
660 ; jne .loop
661 ; ret
662 ;label2 ; some code
663 ;.loop
664 ; ; some more code
665 ; jne .loop
666 ; ret
667 ;In the above code fragment, each JNE instruction jumps to the line immediately before it, because the two definitions of .loop are kept separate by virtue of each being associated with the previous non-local label.
668
669 ;from http://wiki.osdev.org/Interrupts
670 ; if IRQ 6 is sent to the PIC by a device, the PIC would tell the CPU to service INT 0Eh, which presumably has code for interacting with whatever device sent the interrupt in the first place. Of course, there can b
671
672 ; from http://www.techmasala.com/2006/03/31/foundation-stone-3-bios-part-2-the-interrupt-vector-table/:
673 ;Foundation stone #3 – BIOS part 2 – The interrupt vector table
674 ;by Ramesh on Friday,March 31, 2006 @ 9:50 am
675 ;In my post Foundation stone #2 we saw that BIOS is the one that takes in charge when you switch on your PC. After collecting the inventory of available and properly working hardware, the BIOS sets up what is called
676 ;So when the BIOS is done with the inventory of hardware, it initializes a memory space of 1024 bytes starting at 0000:0000h (this is a representation of memory location in the form of segment:offset in hexadecimal)
677 ;The Interrupt Vector Table (IVT) is a mapping of the interrupt number and the memory location in the form of segment:offset. This memory location contains the interrupt code for that particular interrupt. It is th
678
679 ; conventionally [c.f. http://en.wikipedia.org/wiki/Conventional_memory, http://en.wikipedia.org/wiki/Power-on_self-test%5D people agree upon the following memory map … from http://www.supernovah.com/Tutorials/Assem
680 ;Default Memory
681 ;When the computer boots, the BIOS loads the memory with a lot of different data. This data resides in different places throughout memory and we are only left with 630Kb of memory to work with in the middle of every
682 ;All ranges are inclusive
683 ;Address Range (in hex) Size Type Description
684 ;0 – 3FF 1Kb Ram Real Mode Interrupt Vector Table (IVT)
685 ;400 – 4FF 256 bytes Ram BIOS Data Area (BDA)
686 ;500 – 9FBFF 630Kb Ram Free Memory
687 ;9FC00 – 9FFFF 1Kb Ram Extended BIOS Area (EBDA)
688 ;A0000 – BFFFF 128Kb Video Ram VGA Frame Buffer
689 ;C0000 – C7FFF 32Kb Rom Video Bios
690 ;C8000 – EFFFF 160kb Rom Misc.
691 ;F0000 – FFFFF 64Kb
692
693 ; from NASM manual
694 ;Multi-line macros are much more like the type of macro seen in MASM and TASM: a multi-line macro definition in NASM looks something like this.
695 ;%macro prologue 1
696 ; push ebp
697 ; mov ebp,esp
698 ; sub esp,%1
699 ;%endmacro
700
701 ; from http://www.husseinsspace.com/teaching/udw/1996/asmnotes/chaptwo.htm:
702 ;The SHR/SLR instructions
703 ;format:
704 ;SHR destination,1
705 ;SHR destination,CL
706 ; SHL destination,1
707 ; SHL destination,CL
708 ;SHR shifts the destination right bitwise either 1 position or a number of positions determined by the current value of the CL register. SHL shifts the destination left bitwise either 1 position or a number of posit
709 ;example:
710 ;shr ax,1
711 ; shl ax,1
712 ;The first example effectively divides ax by 2 and the second example effectively multiplies ax by 2. These commands are faster than using DIV and MUL for arithmetic involving powers of 2.
713
714 ;****************************
715 ; from Intel Programmer’s Reference Manual
716 ;10.1 Processor State After Reset
717 ;The contents of EAX depend upon the results of the power-up self test. The self-test may be requested externally by assertion of BUSY# at the end of RESET. The EAX register holds zero if the 80386 passed the test.
718 ;DX holds a component identifier and revision number after RESET as Figure 10-1 illustrates. DH contains 3, which indicates an 80386 component. DL contains a unique identifier of the revision level.
719 ;Control register zero (CR0) contains the values shown in Figure 10-2 . The ET bit of CR0 is set if an 80387 is present in the configuration (according to the state of the ERROR# pin after RESET). If ET is reset, th
720 ;The remaining registers and flags are set as follows:
721 ; EFLAGS =00000002H
722 ; IP =0000FFF0H
723 ; CS selector =000H
724 ; DS selector =0000H
725 ; ES selector =0000H
726 ; SS selector =0000H
727 ; FS selector =0000H
728 ; GS selector =0000H
729 ; IDTR:
730 ; base =0
731 ; limit =03FFH
732 ;All registers not mentioned above are undefined.
733 ;These settings imply that the processor begins in real-address mode with interrupts disabled.
734 ;10.2 Software Initialization for Real-Address Mode
735 ;In real-address mode a few structures must be initialized before a program can take advantage of all the features available in this mode.
736 ;10.2.1 Stack
737 ;No instructions that use the stack can be used until the stack-segment register (SS) has been loaded. SS must point to an area in RAM.
738 ;10.2.2 Interrupt Table
739 ;The initial state of the 80386 leaves interrupts disabled; however, the processor will still attempt to access the interrupt table if an exception or nonmaskable interrupt (NMI) occurs. Initialization software shou
740 ; Put pointers to valid interrupt handlers in all positions of the interrupt table that might be used by exceptions or interrupts.
741 ; Change the IDTR to point to a valid interrupt table.
742 ;
743 ;10.2.3 First Instructions
744 ;After RESET, address lines A{31-20} are automatically asserted for instruction fetches. This fact, together with the initial values of CS:IP, causes instruction execution to begin at physical address FFFFFFF0H. Nea
745
746 ; from http://en.wikipedia.org/wiki/Interrupt_descriptor_table
747 ;In the 8086 processor, the IDT resides at a fixed location in memory from address 0x0000 to 0x03ff, and consists of 256 four-byte real mode pointers (256 × 4 = 1024 bytes of memory). In the 80286 and later, the si
748 ; A commonly used x86 real mode interrupt is INT 10, the Video BIOS code to handle primitive screen drawing functions such as pixel drawing and changing the screen resolution.
749
750
751 ; from http://software.intel.com/en-us/articles/introduction-to-x64-assembly
752 ; XOR EAX, EAX ; zero out eax
753 ; MOV ECX, 10 ; loop 10 times
754 ;Label: ; this is a label in assembly
755 ; INX EAX ; increment eax
756 ; LOOP Label ; decrement ECX, loop if not 0
757
758 ; from https://courses.engr.illinois.edu/ece390/books/artofasm/CH06/CH06-5.html#HEADING5-294
759 ; mov ecx, 255
760 ;ArrayLp: mov Array[ecx], cl
761 ; loop ArrayLp
762 ; mov Array[0], 0
763 ;The last instruction is necessary because the loop does not repeat when cx is zero. Therefore, the last element of the array that this loop processes is Array[1], hence the last instruction.
764 ; The loop instruction does not affect any flags.
765
766 ; 2.17.2014 chu’ Ha^n telephoned about obtaining literature on American Philosophy and on US Census Data particularly
767 ; US Census Data on black population expansion into US and into the world …
768 ; following day: couple resembling co^ Be^ and David Lowe seen at Post Office when we tried to mail chu’ Kha’s preserved fruit to father in Michigan
769 ; from http://randomascii.wordpress.com/2012/12/29/the-surprising-subtleties-of-zeroing-a-register/
770 ; also see http://navet.ics.hawaii.edu/~casanova/courses/ics312_spring14/slides/ics312_bits_2.pdf
771 ;Tabula rasa
772 ;The x86 instruction set does not have a special purpose instruction for zeroing a register. An obvious way of dealing with this would be to move a constant zero into the register, like this:
773 ;mov eax, 0
774 ;That works, and it is fast. Benchmarking this will typically show that it has a latency of one Sandybridge diecycle the result can be used in a subsequent instruction on the next cycle. Benchmarking will also sh
775 ;Its too big
776 ;The x86 instruction used to load a constant value such as zero into eax consists of a one-byte opcode (0xB8) and the constant to be loaded. The problem, in this scenario, is that eax is a 32-bit register, so the co
777 ;B8 00 00 00 00 mov eax, 0
778 ;Instruction size does not directly affect performance you can create lots of benchmarks that will prove that it is harmless but in most real programs the size of the code does have an effect on performance. T
779 ;Smaller alternatives
780 ;Many RISC architectures have a zero register in order to optimize this particular case, but x86 does not. The recommended alternative for years has been to use xor eax, eax. Any register exclusive ored with itself
781 ;33 C0 xor eax, eax
782 ;Careful micro-benchmarking will show that this instruction has the same one-cycle latency and three-per-cycle throughput of mov eax, 0 and it is 60% smaller (and recommended by Intel), so all is well.
783 ;Suspicious minds
784 ;If you really understand how CPUs work then you should be concerned with possible problems with using xor eax, eax to zero the eax register. One of the main limitations on CPU performance is data dependencies. Whil
785 ;1: add eax, 1
786 ;2: mov ebx, eax
787 ;3: xor eax, eax
788 ;4: add eax, ecx
789 ;Careful micro-benchmarking will show that this instruction has the same one-cycle latency and three-per-cycle throughput of mov eax, 0 and it is 60% smaller (and recommended by Intel), so all is well.
790 ;Ideally we would like our awesome out-of-order processor to execute instructions 1 and 3 in parallel. There is a literal data dependency between them, but a sufficiently advanced processor could detect that this de
791 ;It turns out that for x86 processors have for years handled xor of a register with itself specially. Every out-of-order Intel and AMD processor that I am aware of can detect that there is not really a data dependen
792
793
794 ; from http://stackoverflow.com/questions/4909563/why-should-code-be-aligned-to-even-address-boundaries-on-x86
795 ;Because the (16 bit) processor can fetch values from memory only at even addresses, due to its particular layout: it is divided in two “banks” of 1 byte each, so half of the data bus is connected to the first bank
796 ; bank 1 bank 2
797 ;+——–+——–+
798 ;| 8 bit | 8 bit |
799 ;+——–+——–+
800 ;| | |
801 ;+——–+——–+
802 ;| 4 | 5 | 803 ;+——–+——–+
804 ;| 2 | 3 |
805 ;+——–+——–+
806 ;| 0 | 1 |
807 ;+——–+——–+
808 ; \ / \ /
809 ; | | | |
810 ; | | | |
811 ; data bus (to uP)
812
813 ;Now, since this fetch limitation, if the cpu is forced to fetch values which are located on an odd address (suppose 3), it has to fetch values at 2 and 3, then values at 4 and 5, throw away values 2 and 5 then join
814 ; That’s why is better having code (and data!) on even addresses.
815 ;PS: On 32 bit processors, code and data should be aligned on addresses which are divisible by 4 (since there are 4 banks).
816 ;Hope I was clear. 🙂
817 ;share|improve this answer
818 ;answered Feb 5 ’11 at 23:02
819 ;BlackBear
820 ;9,42131746
821 ;bio
822 ;website google.it
823 ;location Trento, Italy
824 ;age 19
825
826 ; from http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/
827 ;Conclusion: On recent Intel processors, data alignment does not make processing measurably faster. Data alignment for speed is a myth.
828 ;Acknowledgement: I am grateful to Owen Kaser for pointing me to the references on this issue.
829 ;http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/
830
831
832 ;\[ d E S F a s a d o \]
833
834
835
836
837
838 ;11/9/99
839
840
841
842
843
844
845
846
847
848
849
850
851
852 ;DOS: nasm -f bin -o your_file.com your_file.asm
853 ;1)mov ax,your_segment
854 ; mov ds,ax
855
856 ;2) mov ax,[your_segment]
857 ; mov ds,ax
858
859
860 ;first of all you cant use mov ds,something… secondly you are trying to put
861 ;in DS an offset of the current CS.
862
863 ;The second example is what you have to do.
864
865 ;hope this help..
866
867 ;–
868 ;[ yOu HaVe To SeArCh AnD sEaRcH, rElAtE iNfO, pRoBe AnD pRobE, tHeRe Is NoT
869 ;aNoThEr WaY ]
870 ;[ dOnT nEvEr gIvE uP, uSe YoR bRaIn At LeAsT aT 1o0% ]
871
872 ;ASM CodER, PC HW & Electrical Technitian
873 ;desf…@ciudad.com.ar
874 ;http://members.xoom.com/desfasado >>> dENarixs OS Project
875 ;UIN: 30796163
876
877
878
879
880
881
882
*************************************************************************
testNASM disassembly.txt
Current working directory: C:\Users\LaptopUser\My Programs\Projects\CodeLite Projects\testNASM
Running program: “C:\Users\LaptopUser\My Programs\nasm-2.10.09-win32\nasm-2.10.09\ndisasm.exe” -b 16 testNASM.bin
00000000 EA6600C007 jmp word 0x7c0:0x66
00000005 48 dec ax
00000006 6F outsw
00000007 7065 jo 0x6e
00000009 205765 and [bx+0x65],dl
0000000C 6C insb
0000000D 6C insb
0000000E 0000 add [bx+si],al
00000010 0000 add [bx+si],al
00000012 0000 add [bx+si],al
00000014 0000 add [bx+si],al
00000016 0000 add [bx+si],al
00000018 0000 add [bx+si],al
0000001A 0000 add [bx+si],al
0000001C 0000 add [bx+si],al
0000001E 0000 add [bx+si],al
00000020 0000 add [bx+si],al
00000022 0000 add [bx+si],al
00000024 0000 add [bx+si],al
00000026 0000 add [bx+si],al
00000028 0000 add [bx+si],al
0000002A 0000 add [bx+si],al
0000002C 0000 add [bx+si],al
0000002E 0000 add [bx+si],al
00000030 0000 add [bx+si],al
00000032 0000 add [bx+si],al
00000034 0000 add [bx+si],al
00000036 0000 add [bx+si],al
00000038 0000 add [bx+si],al
0000003A 0000 add [bx+si],al
0000003C 0000 add [bx+si],al
0000003E 0000 add [bx+si],al
00000040 0000 add [bx+si],al
00000042 0000 add [bx+si],al
00000044 0000 add [bx+si],al
00000046 0000 add [bx+si],al
00000048 0000 add [bx+si],al
0000004A 0000 add [bx+si],al
0000004C 0000 add [bx+si],al
0000004E 0000 add [bx+si],al
00000050 0000 add [bx+si],al
00000052 0000 add [bx+si],al
00000054 0000 add [bx+si],al
00000056 0000 add [bx+si],al
00000058 0000 add [bx+si],al
0000005A 0000 add [bx+si],al
0000005C 0000 add [bx+si],al
0000005E 0000 add [bx+si],al
00000060 0000 add [bx+si],al
00000062 0000 add [bx+si],al
00000064 0000 add [bx+si],al
00000066 B8C007 mov ax,0x7c0
00000069 8ED8 mov ds,ax
0000006B B8C007 mov ax,0x7c0
0000006E 8ED0 mov ss,ax
00000070 BC4E00 mov sp,0x4e
00000073 E80000 call word 0x76
00000076 E80D00 call word 0x86
00000079 E81000 call word 0x8c
0000007C E82100 call word 0xa0
0000007F E82A01 call word 0x1ac
00000082 E82701 call word 0x1ac
00000085 C3 ret
00000086 B800B8 mov ax,0xb800
00000089 8EC0 mov es,ax
0000008B C3 ret
0000008C B99F0F mov cx,0xf9f
0000008F BB0100 mov bx,0x1
00000092 39CB cmp bx,cx
00000094 7709 ja 0x9f
00000096 26C60770 mov byte [es:bx],0x70
0000009A 83C302 add bx,byte +0x2
0000009D EBF3 jmp short 0x92
0000009F C3 ret
000000A0 26C606000068 mov byte [es:0x0],0x68
000000A6 26C60602006F mov byte [es:0x2],0x6f
000000AC 26C606040070 mov byte [es:0x4],0x70
000000B2 26C606060065 mov byte [es:0x6],0x65
000000B8 26C606080020 mov byte [es:0x8],0x20
000000BE 26C6060A0077 mov byte [es:0xa],0x77
000000C4 26C6060C0065 mov byte [es:0xc],0x65
000000CA 26C6060E006C mov byte [es:0xe],0x6c
000000D0 26C60610006C mov byte [es:0x10],0x6c
000000D6 684820 push word 0x2048
000000D9 684F20 push word 0x204f
000000DC 685020 push word 0x2050
000000DF 684520 push word 0x2045
000000E2 685720 push word 0x2057
000000E5 684520 push word 0x2045
000000E8 684C20 push word 0x204c
000000EB 30DB xor bl,bl
000000ED 8A1E4800 mov bl,[0x48]
000000F1 26881E3C00 mov [es:0x3c],bl
000000F6 8A1E4600 mov bl,[0x46]
000000FA 26881E3E00 mov [es:0x3e],bl
000000FF 8A1E4400 mov bl,[0x44]
00000103 26881E4000 mov [es:0x40],bl
00000108 8A1E4200 mov bl,[0x42]
0000010C 26881E4200 mov [es:0x42],bl
00000111 8A1E4000 mov bl,[0x40]
00000115 26881E4400 mov [es:0x44],bl
0000011A 8A1E3E00 mov bl,[0x3e]
0000011E 26881E4600 mov [es:0x46],bl
00000123 8A1E3C00 mov bl,[0x3c]
00000127 26881E4800 mov [es:0x48],bl
0000012C 8A1E3C00 mov bl,[0x3c]
00000130 26881E4A00 mov [es:0x4a],bl
00000135 30DB xor bl,bl
00000137 5B pop bx
00000138 26881E3800 mov [es:0x38],bl
0000013D 5B pop bx
0000013E 26881E3600 mov [es:0x36],bl
00000143 5B pop bx
00000144 26881E3400 mov [es:0x34],bl
00000149 5B pop bx
0000014A 26881E2E00 mov [es:0x2e],bl
0000014F 5B pop bx
00000150 26881E2C00 mov [es:0x2c],bl
00000155 5B pop bx
00000156 26881E2A00 mov [es:0x2a],bl
0000015B 5B pop bx
0000015C 26881E2800 mov [es:0x28],bl
00000161 30DB xor bl,bl
00000163 8A1E0500 mov bl,[0x5]
00000167 26881E1400 mov [es:0x14],bl
0000016C 8A1E0600 mov bl,[0x6]
00000170 26881E1600 mov [es:0x16],bl
00000175 8A1E0700 mov bl,[0x7]
00000179 26881E1800 mov [es:0x18],bl
0000017E 8A1E0800 mov bl,[0x8]
00000182 26881E1A00 mov [es:0x1a],bl
00000187 8A1E0900 mov bl,[0x9]
0000018B 26881E1C00 mov [es:0x1c],bl
00000190 8A1E0A00 mov bl,[0xa]
00000194 26881E1E00 mov [es:0x1e],bl
00000199 8A1E0B00 mov bl,[0xb]
0000019D 26881E2000 mov [es:0x20],bl
000001A2 8A1E0C00 mov bl,[0xc]
000001A6 26881E2200 mov [es:0x22],bl
000001AB C3 ret
000001AC EBFE jmp short 0x1ac
000001AE F4 hlt
000001AF 0000 add [bx+si],al
000001B1 0000 add [bx+si],al
000001B3 0000 add [bx+si],al
000001B5 0000 add [bx+si],al
000001B7 0000 add [bx+si],al
000001B9 0000 add [bx+si],al
000001BB 0000 add [bx+si],al
000001BD 0000 add [bx+si],al
000001BF 0000 add [bx+si],al
000001C1 0000 add [bx+si],al
000001C3 0000 add [bx+si],al
000001C5 0000 add [bx+si],al
000001C7 0000 add [bx+si],al
000001C9 0000 add [bx+si],al
000001CB 0000 add [bx+si],al
000001CD 0000 add [bx+si],al
000001CF 0000 add [bx+si],al
000001D1 0000 add [bx+si],al
000001D3 0000 add [bx+si],al
000001D5 0000 add [bx+si],al
000001D7 0000 add [bx+si],al
000001D9 0000 add [bx+si],al
000001DB 0000 add [bx+si],al
000001DD 0000 add [bx+si],al
000001DF 0000 add [bx+si],al
000001E1 0000 add [bx+si],al
000001E3 0000 add [bx+si],al
000001E5 0000 add [bx+si],al
000001E7 0000 add [bx+si],al
000001E9 0000 add [bx+si],al
000001EB 0000 add [bx+si],al
000001ED 0000 add [bx+si],al
000001EF 0000 add [bx+si],al
000001F1 0000 add [bx+si],al
000001F3 0000 add [bx+si],al
000001F5 0000 add [bx+si],al
000001F7 0000 add [bx+si],al
000001F9 0000 add [bx+si],al
000001FB 0000 add [bx+si],al
000001FD 0055AA add [di-0x56],dl
Program exited with return code: 0
********************************************************
testNASM.bin

nasm and effect of the org directive
NASM and the effect of changing the ORG directive from note “nasm and effect of org directive” based on tutorials from http://www.supernovah.com/Tutorials/index.php website by Alex Jorg….
![]()
http://www.supernovah.com/Images/Signature.png ………:
:
asm.txt:
asm.txt:
[BITS 16]
[ORG 0x0]
jmp 0x0:Start
Start:
cli
mov AX,0x9000
mov SS,AX
mov SP,0xFB00
sti
cli
hlt

listing.txt:
1 [BITS 16]
2 [ORG 0x0]
3
4 00000000 EA[0500]0000 jmp 0x0:Start
5
6 Start:
7 00000005 FA cli
8 00000006 B80090 mov AX,0x9000
9 00000009 8ED0 mov SS,AX
10 0000000B BC00FB mov SP,0xFB00
11 0000000E FB sti
12
13 0000000F FA cli
14 00000010 F4 hlt
15
16 00000011 00<rept> times 510 – ($ – $$) db 0
17 000001FE 55AA dw 0xAA55
ndisasm.txt:
00000000 EA05000000 jmp word 0x0:0x5
00000005 FA cli
00000006 B80090 mov ax,0x9000
00000009 8ED0 mov ss,ax
0000000B BC00FB mov sp,0xfb00
0000000E FB sti
0000000F FA cli
00000010 F4 hlt
*******************************
asm.txt:
[BITS 16]
[ORG 0x7C00]
jmp 0x0:Start
Start:
cli
mov AX,0x9000
mov SS,AX
mov SP,0xFB00
sti
cli
hlt
listing.txt:
1 [BITS 16]
2 [ORG 0x7C00]
3
4 00000000 EA[0500]0000 jmp 0x0:Start
5
6 Start:
7 00000005 FA cli
8 00000006 B80090 mov AX,0x9000
9 00000009 8ED0 mov SS,AX
10 0000000B BC00FB mov SP,0xFB00
11 0000000E FB sti
12
13 0000000F FA cli
14 00000010 F4 hlt
15
16 00000011 00<rept> times 510 – ($ – $$) db 0
17 000001FE 55AA dw 0xAA55
ndisam.txt:
00000000 EA057C0000 jmp word 0x0:0x7c05
00000005 FA cli
00000006 B80090 mov ax,0x9000
00000009 8ED0 mov ss,ax
0000000B BC00FB mov sp,0xfb00
0000000E FB sti
0000000F FA cli
00000010 F4 hlt
3.1.2014 Midlife Crisis “who do you love” (gia ba?o said bad boy to george thoroughgood)
3/1/2014
“who do you love”: di` tu+ said last year when we first met “sao kho^ng ai la`m nu~ng vo+’i bo^’ he^’t la`m nu~ng vo+’i me. kho^ng a`” … President Obama on tv today 3/3/2014 on ukraine-russia … no we la`m nu~ng both ba ma’ equally … when you’ve met and know us for longer time …
Published on Nov 4, 2013 [the guy who does ddi.nh and die^~m’s pool resembles this guy on youtube who covers sawyer brown grateful song …]
Gia Ba?o said “xin dda ta.” to everything and everyone including a young woman having lunch alone at Pho+? Ba` Da^.u Co^ng Ly’ on 3/3/2014 … on way back he slept out in the car with ba’c Ty’ in parking lot at 99 ranch … thank you ba’c … lu+o+ng ta^m cho sao suggested him …but once ba’c Ty’ realizes what’s happening with help of other people in parking lot he assumes idiot pose instead of gia ba?o grace pose …
Thank God For You
By Sawyer Brown E A E
Well I’ve been called a self-made man E B7 E
Girl don’t you believe it’s true
E A E
I know exactly how lucky I am E B7 E
When I’m gettin’ this close to you A C#m
It’s high time I’m giving some praise
A C#m B A
To those that got me where I am toda-a-a-y E
I got to thank mama for the cookin’
A
Daddy for the whuppin’ E B7
The devil for the trouble that I get into E A
I’ve got to give credit where credit is due E
I thank the bank for the money B7 E
Thank God for you
http://www.youtube.com/watch?v=y-9KSDl3xzA
*******************************************************
To^n DDi.nh got too sleepy to drive home from visit to san francisco china town–light lunch at place ba’c vinh david ho^`ng visited and were about to exchange some clothing but did not … thought luna lee gaygeum player was based here but was not …. but resemblance from clothing store and from publicdisgrace.com are based in san Francisco … off to see the rain wizard for reward … di` ba suggested at breakfast to gia ba?o and asked us on trip “co’ ddo’i kho^ng” … the sparrows and blue jays but not doves and crows and falcons around ddi.nh and die^~m’s house are rather tiny compare to their correspondences/equivalents in michigan … … black version of Wizard of OZ on tv… but the rain prayer could certainly be san Francisco’s own … black homeless man “still wet” … still has a heart still has humanity co’ nha^n co’ lu+o+ng ta^m after all that lifting … don’t bring me down … girl making pointing finger dance of the supreme don’t go around breaking my heart you and you and you don’t let/bring me down again … people including steve job resemblances were happy and also expressing short-change not given enough time/attention … get some bean cake from china town seems that our lunch of a byte each of crab, duck, noodle, vegetable, soup and no more than a bite might have reflected north korea … di` ba made vietnamese canh rau to^m and rib and du+a muo^’i for supper and discussed lending ye^’n earings mother bought with her from china town last year … reminding to^n an now of ba’c gia’o ha`n’s chi. mai absorbtion/integration into american life via anh kha’nh … woman at pho+? place and her waitresses … which anh kha’nh resembles ca^.u nha^’t and so does to^n ddi.nh … one wonders about gia ba?o who gave ba’c ty’ his play ball in exchange for ba’nh canh sesame ball ba’nh da’n and gia ba?o’s absorbtion/integration of his parents’ lives into his own and north korea integration into american life via basketball which might be similar to how to^nan absorbs/integrates the world of pornography into his academic world of mathematics etc. to the point where he could view a pornographic picture with enouh familiarty ~ family ~ gia to experience no arousal … see discussion of monk walking into a house of prostitution [complete with its shadow world play on the family characters “tu’ ba`” “ma’/me.” “ba” “tu+” “na(m” “sa’u” etc.] unaffected as a lotus in a mud pond ga^`n bu`n ma` cha(?ng ho^i tanh mu`i bu`n in other notes … and could sometimes extract mathematical information from the picture besides … and vice versa the world of porn absorbed/integrated to^nan and his family and academic life….noah’s café or noah’s bagels seems to be closed and in the dark …– half way home and must defer the driving to di` ba co^ die^~m … he was “on call” all day and all night yesterday and the day before that and the day before that …
beautiful couples on the streets … at first unbalanced with the gal more beautiful than the guy then with gal and guys equally beautiful … gia ba?o various attempts to have his parents together …
following picture–supposedly anh DDo^’ng con ba’c gia’o ha`n telephone mother requesting support to write gia pha?– summarizes the various relationships: computer segment:offset ORG addressing scheme …, europe-ukraine-russia, china-north-korean-america, di`ba’s-pregnancy, gia-ba?o-di`-ba-his parents, to^nan-academic-world-pornographic-world, … and if one can see and accepts le^ duye^n II massage parlor and gia ba?o running around the house naked or playing naked with di` ba etc. then one would come to see and accept how the west or America might eventually come to view and accept North Korea and China … at first north korea or gia ba?o might seem irritating and seems an instrument–especially when they’re angry and want to ddo^’I dda’p with you– of China or di` ba to criticize or jibe the west/America or non-pornographic sensibilities … but once one sees through the relationship one can then “normalize” it in one’s sensibilities … in fact one finds that if one tracks the child closely literally word to word–jesus parabolic parables often can be simplified to the Lord’s Prayer request for food and sleep as Gia Ba?o demonstrate to di` ba … when the child’s needs are not met … metart … he will the brightest of bright stars …. “…’Cause I gonna make you see / There’s nobody else here / No one like me / I’m special so special / I gotta have some of your attention give it to me…” http://www.azlyrics.com/lyrics/pretenders/brassinpocket.html pretender ~ la’o ~ lao ~ Lao-tzu ~ la`o ~ a table of Laotian resemblance were at the Chinese restaurant after others have left … 3/25/2014
Old man take a look at my life
I’m a lot like you
I need someone to love me
the whole day through
Ah, one look in my eyes
and you can tell that’s true.
Lullabies, look in your eyes,
Run around the same old town.
Doesn’t mean that much to me
To mean that much to you.
I’ve been first and last
Look at how the time goes past.
But I’m all alone at last.
Rolling home to you. http://www.azlyrics.com/lyrics/neilyoung/oldman.html
— one finds that the child is quite “adorable” in the words of di` ba instead of “what child is this?” Christmas carol … but then the adorable child will run away from you because then you will be on the receiving instead of the giving end of love …. and eventually you would wisened up and aim for the Middle Path of giving attention/focus/time/love …
by the way, the weaponry … tanks etc….. American woman’s “war machine” http://www.lyricsbay.com/who_guess_american_woman_lyrics-guess_who.html [3/25/2014 before to^nan “blew up” in following notes he mentions to to^nddi.nh honey and di` ba how a marilyn monroe movie seemingly in tha(`ng bo+`m’s fashion compares a gun to an air conditioner … and before that to^nan mentions how “don’t stare a {trojan} gift horse in the mouth” the native american indians got the plague from the fancy blankets given them by the europeans … father’s dde`n mansion … dde`n ke’o qua^n … but it just goes to say that it’s all ta^m/trinity/conscience sharing …whether it’s “ghost in the machine” in the computer operating system that violates 10 commandments, dust on fan in die^.p and ye^’n’s room, under refrigerator, mold in laundry machine etc, carbon in grill etc. orange bits in juicer, rust in ice maker etc. … as long as you put in the work cleaning, maintaining, serving and servicing the “machines” the american war machines, they would serve you well … ]… in the background of the picture would represent correspondingly some enfant terrible from the west and the child’s mother or father .. perhaps some virgin mary/maria or joseph …. the east might very well say “what child is this” http://www.azlyrics.com/lyrics/joshgroban/whatchildisthis.html to have unleashed such terrible toys of a weaponry upon the east … to which the west baby jesus would probably say “let those among you without terrible sins–consider your culinary utensils or consider the plants’s … ddi.nh pointed out to die^~m a supposedly carnivorous plant in china town … and animals’ teeth and claws and other offensive/defensive appendages– throw the first stone …” or “we have seen the enemy and he is us” …

external circumstances forced her to play big sister and to love little brother exclusive [for protection ba?o ve^. purposes of tender loving inside from the hard facts of life outside; exclusive = * star if not sun] of everyone else who will be remonstrated and blamed for bringing about the circumstances unless they can break through the wall of seeming provocation by her and her little brother by tracking both siblings closely as though they are the north star of command/direction to listen to their needs and thereby to reach the siblings and share their “insider” tu?i tha^n cinderella love …: with application to di` ba-gia ba?o .. china-north-korea …. ukraine-russia …. tha?o and husband …. tha?o resembles to^nan’s teacher in dda`la.t who resembles co^ Nga ~ moon ca^.u kie^.m while tha?o’s husband resembles ca^.u nha^’t ~ nha^.t ~ japan …. recently when china launches for the moon, north korea supports and launches intercontinental missiles … to insiders it’s love … to outsiders … in a manner of speaking song “don’t imagine you’re too familiar” at Yanagi Restaurant on Sunday previous … such as japan it seems a provocation … japan heightens defense of intercontinental missiles said it will track and bring down any missiles coming from North Korea that passe its air space … … although it could also be seen as comedic …. sushi restaurant chefs have laughed at to^nan previously in dallas, tx … support of north korea since it lends seriousness to north korea’s and therefore china’s firework endeavors …as well japan supports the illusion of having “division” ~ “the {great} wall” ~ “gia” of the N & S Korea and China …

{around 1982-1983 when to^n an left highschool for college to study “grendel” by John Champlin Gardner, Jr. (July 21, 1933 – September 14, 1982) … who resembles Steve Job of Apple Computer … whose resemblance was spotted with wife at babies r us a couple of days ago 3/7/2014 ….was an American novelist, essayist, literary critic and university professor. He is perhaps most noted for his novel Grendel, a retelling of the Beowulf myth from the monster’s point of view. http://en.wikipedia.org/wiki/John_Gardner_(novelist)
Korean Air Lines Flight 007 (also known as KAL007 and KE007[note 2]) was a scheduled Korean Air Lines flight from New York City to Seoul via Anchorage. On September 1, 1983, the airliner serving the flight was shot down by a Soviet Su-15 interceptor near Moneron Island, west of Sakhalin Island, in the Sea of Japan. The interceptor’s pilot was Major Gennadi Osipovich. All 269 passengers and crew aboard were killed, including Lawrence McDonald, a sitting member of the United States Congress. The aircraft was en route from Anchorage to Seoul when it flew through prohibited Soviet airspace around the time of a U.S. reconnaissance mission.
The Soviet Union initially denied knowledge of the incident,[2] but later admitted the shootdown, claiming that the aircraft was on a spy mission.[3] The Politburo said it was a deliberate provocation by the United States[4] to test the Soviet Union’s military preparedness, or even to provoke a war. The White House accused the Soviet Union of obstructing search and rescue operations.[5] The Soviet military suppressed evidence sought by the International Civil Aviation Organization (ICAO) investigation, notably the flight data recorders,[6] which were eventually released eight years later after the collapse of the Soviet Union.[7]
The incident was one of the tensest moments of the Cold War and resulted in an escalation of anti-Soviet sentiment, particularly in the United States. The opposing points of view on the incident were never fully resolved. Consequently, several groups continue to dispute official reports and offer alternative theories of the event. The subsequent release of KAL 007 flight transcripts and flight recorders by the Russian Federation has clarified some details.
As a result of the incident, the United States altered tracking procedures for aircraft departing Alaska. The interface of the autopilot used on airliners was redesigned to make it more ergonomic.[8]
http://en.wikipedia.org/wiki/Korean_Air_Lines_Flight_007
… also there is a lot of insider love in the american woman’s weaponry … even love between a mother/father and child … though to outsiders it seems not love but monstrous inventions … di` die^.p “tu+” and “qua^n” …: sobering thought … “She” is always the universal mother who would provide sustenance to one and all regardless … ye^’n bought mother some chinese pastry today 3/3/2014 … so of course she her first love is given first to those immediately in need but she also loves everyone else and should they call on her she will also love them … … eagles’ song “Lying eyes” … …. don’t divide and conquer with her motherly instincts … thus similar to tro.ng thu?y my. cha^u … di` ba listens to youtube broadcast of how to make cow/ox tail soup while cooking pigs’ feet from vietnam “… o+? be^n na`y nu+o+’c so^i su`ng su.c ro^`i …” … she would be a double-agent anytime … 3/3/2014 ye^’n gave mother chinese pastry … after to^nan bought chinese pastry from china town with elephant ears two of each times five plus one and customers tha’i ha’i jewelry “apples” from the jewelry apple tree in china town curios shop … ddi.nh has jewel cd out… recall that the serpent effectively feeds …by tempting eve to tha’i ha’i .. the apple ….. the porn with the mathematics for example has the lamps of to^n ddi.nh as stage … chi. chi’nh “smuggles”/passes on to to^nan …who was then a creature of the heart and soon of the sex and little in the way of the head instead of a creature of the head as now …ba`y ve~ so+n phe^’t information way over his head then about 10-12 years of age about the mathematics of geodesics over her father tue^. ddi?nh cao tri’ tue^. loa`i ngu+o+`i .. gia ba?o gray sie^u khi? monkey in red cape … her serpentine-and-eve double-agent motherly nature …as well as ye^’n’s, gia ba?o, to^nan, to^nan’s mother father, everyone’s nature … is meant to enable “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well” … the universal motherly double-agency would equalize and mollify the monstrous weaponry so that “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well” …
gia ba?o sings du+o+ng ngo.c tha’i–ye^’n’s singer friend supposedly– for di` ba in presence of ba` and honey … ” …kho^ng dda’nh ma` ddau” and “ne^’u tha^.t ti`nh thu+o+ng nhau thi` xin thu+o+ng cho cho.n to+’i khi so^ng ca.n dda’ lu.n xin ddu+`ng phu. nhau …”
http://whattalking.com/picasa/PegPlusCat
ca dao [viettoday ca dao with prof Quyen Di] Vietnam: “ddi cho bie^’t ddo’ bie^’t dda^y; o+? nha` vo+’I me. bie^’t nga`y na`o kho^n” …. 3/7/2014 home alone with mother all day di` ba supposedly went to do health insurance for “tu+” …
“the anti said: ↑
dude, what the fuck?
Do you have a problem with Mary feeding Jesus?”
https://whyweprotest.net/community/threads/christan-appreciation-thread.114191/page-2

arabian mother and child at fabric r us a few days ago 3/7/2014….
In 1930, Iowa artist Grant Wood painted American Gothic [mind-her-own-business gothiccashier in Pleasanton Mall … Sunday previous 3/7/2014]. The models he used for the painting were his sister Nan Wood Graham and his dentist, Byron McKeeby. Here they are next to the painting:


http://kottke.org/12/02/the-models-for-american-gothic
http://williamjepma.files.wordpress.com/2013/05/images2.jpg?w=360&h=140
![]()
desire for sunlight max out during the dark winter days … around Christmas New Year : … but, … media or other sources suggested “i heard it through the grapevines not much longer will you be mine …”. .. march 21 vernal equinox is coming up soon ….
{3/7/2014 incidentally: not quite Vietnam War Era Paris Peace Talk –shades of Henry Kissinger spotted somewhere … ca’c di` mentions “mi” … to^nan’s “mi” computer keyboard .. “mi” con chi. trang anh ba(`ng … ta`o tha’o’s singer–and not quite Batavia, Illinois but …
The Sunlight Dialogues [3/21/2014 jehovah witness in michigan and a couple of black gentlemen and a rooster-haired gentlewoman and bearded long-haired blond construction guy and blond guy short cut across grass lawn at mcdonald in dublin, california a couple of days ago … u’ ly` u’ linh black boyfriend and wedding came to mind:
dichotomy situation indicates resolution by Middle Path “law and order but as though magic; magic but as though law and order”, “because of see/hear/say no evil/magic/light: have light but as though in darkness; in darkness but as though have light” … Arthur Koestler’s “Darkness at Noon” …
the “law” or “magic” of instantaneous and simultaneous biblical “in the image” ….
I’m already there
Take a look around
I’m the sunshine in your hair
I’m the shadow on the ground
I’m the whisper in the wind
I’m your imaginary friend
And I know I’m in your prayers
Oh I’m already there
http://www.azlyrics.com/lyrics/lonestar/imalreadythere.html
“Morning Has Broken”
CAT STEVENS LYRICS
Morning has broken, like the first morning
Blackbird has spoken, like the first bird
Praise for the singing, praise for the morning
Praise for the springing fresh from the world
Sweet the rain’s new fall, sunlit from heaven
Like the first dewfall, on the first grass
Praise for the sweetness of the wet garden
Sprung in completeness where his feet pass
Mine is the sunlight, mine is the morning
Born of the one light, eden saw play
Praise with elation, praise every morning
God’s recreation of the new day
Writer(s): Dave Mackay, Eleanor Farjeon, Chris Hazell, Johnny Arthey, Hans Guenter Heumann, James Merrill Brickman, Yusuf Islam, Charles Boone, Noel Kelehan
Copyright: Cat Music Limited, Rosette Music Ltd., Dick James Music Ltd., Valentine Music Corp., Ed. Deutsche Grammophon, Universal Tunes A.D.O. Songs Of Univers, Cookaway Music Ltd., Brickman Songs, Sony/ATV Cross Keys Publishing, Bosworth Gmbh, Cat Music Ltd.
http://www.azlyrics.com/lyrics/catstevens/morninghasbroken.html
] is a 1972 novel by the American author John Gardner.
The novel is set in the 1960s in Batavia, New York. [near “hit and run” near miss threat at gas station intersection before reaching gate of fermilab in batavia, il just to^nan packed his bag for home in michigan …: “tu+” co^ Die^.p ran a stop sign driving To^nAn to 99 ranch in her Honda to get some lottery tickets … supposedly Ye^’n felt sleepy driving home to Dublin from San Jose around 9:00pm-12:00 midnight …
3/25/2014 father reports chi. Ha^n’s father who had been staying with tu’ and nga and their daughter in san jose is at ba’c tue^. in michigan visiting : voodoo child … hi.t … that’s a miss …

from note 3.11.2014 need to avoid stack-heap collision in a well-designed computer operating system …: “spirituals in concert” Kathleen Battle’s song “sinners don’t let this harvest past”:
{3/19/2014 need for or existence of boundaries/soul/seol:
Programmer’s Reference Manual suggests that protected mode implement various “stack-like” structure for push-pop-ing protected structures via descriptor tables such as GDT, IDT, etc.
from testNASM.asm:
; SAFEWAY grocery …
%macro SAFECALL 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safecallinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
call %1
%endmacro
%macro SAFEPUSH 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safepushinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
push %1
%endmacro
%macro SAFEPOP 1
; cmp SP, stacksegment
; jl safecallinterrupt
; safepopinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
pop %1
%endmacro
%macro SAFERET 1
; cmp SP, stacksegment
; jl safecallinterrupt
; saferetinterrupt int 5
bound SP, stacklowerbound + 4 + 4 ;
ret %1
%endmacro}
] It follows Batavia police chief Fred Clumly in his pursuit of a magician known as the Sunlight Man, a champion of existential freedom and pre-biblical Babylonian philosophy. As Clumly believes in absolute law, order, justice and a Judeo-Christian world view, the two butt their ideological heads in a number of dialogues, all recorded on audiocassette by Clumly. Each of these two characters attempts to exert power over the other—Clumly with the law behind him and the Sunlight Man with his magic and violence—until they wear down not only each other, but many of the other characters with whom they come into contact. A myriad of side-stories provides background for the plot. http://en.wikipedia.org/wiki/The_Sunlight_Dialogues
PANO – The Paris Peace Talks on the Vietnam War were held in Paris, France from May 15th, 1968 to January 27th, 1973. It was the leading international event and major topic for the world press and opinion, and the international press and opinion “front” made a large contribution to Vietnam’s victory in that historic negotiation.
Bringing the Vietnam War to Americans’ bedrooms
According to former Ambassador Nguyen Khac Huynh, member of the delegation of the Democratic Republic of Vietnam (DRV), the selection of Paris as the location for the negotiation created favourable conditions for the Vietnamese side. Paris, as the capital city of France, was seen as the centre of Europe, from which news and information could spread to the West, the USA and the world very quickly.
http://talkvietnam.com/2013/01/press-and-media-contribute-to-vietnams-victory-at-paris-peace-talks/
https://stoppauseplayfastforwardrewindejectrecord.net/wp-content/uploads/2014/03/ef153-tensor.jpg
http://www.yeuanhvan.com/culture/1364-love-story-of-my-chau-and-trong-thuy
http://www.arts-wallpapers.com/military/KoreanWar/01/Korean-War.jpg
to^n an remembers how he watched internet porn for the first time around the 50th playboy anniversary–with girl resembling anh Lu+o+ng Duye^n Trinh– and felt and thought that it would interfere with family or “gia” … father went to hospital for drinking wine and got dizzy while to^nan was watching porn … “what about family” … so he elected to withdraw from watching porn altogether … but website bangbros must have prompted his conscience to “return” to porn and pay off to advertisement website adultfriendfinder.com … and somehow one thing leads to another …
we were both young and unabashed
we took what life offered
when the folks were distracted
or too tired to care
with a frost on the land
the fates forced our hand
your dresses fit tighter
with the spring in the air
http://www.jamesmcmurtry.com/lyrics/tlwl.htm#10
{3/3/2014 after ba` da^.u co^ng ly’ … with russia-ukraine and washington dc snow on tv …: http://lyric.tkaraoke.com/17551/Tinh_Ca.html people “da(‘t di`u nhau va`o dde^’n ca` (cho+’n) mau …” near bridge: ca` cho+’n mau is the Middle Path … ca` mau is in the neighborhood of Ba.c Lie^u …. it seems contradictory http://www.youtube.com/watch?v=FpzkiFeblzA da(‘t di`u “lean on me” pairs with ca` cho+’n “ignore” … ky` duye^n ca` chua ca` cho+’n at an nam restaurant 3/2/2014 … and yet as explained below about the nature of the Middle Path … it’s the fine balance that enable you to “have but as though have not, have not but as though have” … or “the best of both worlds” …
Tấm áo nâu ! Những mẹ quê chỉ biết cần lao ….. ba` me. que^ guo^’c cu?a tha?o at bobo …
Những trẻ quê bạn với đàn trâu, áo ơi
Tấm áo nâu ! Rướn mình đi từ cõi rừng cao
Dắt dìu nhau vào đến Cà Mâu, áo ơi
Tình Ca Tác giả: Phạm Duy}
.. in the manner of actress betty white “I’ll make it worth your while/time …” family and everything …. and he found familiarity of faces and feelings and memories of family or gia in the porn characters and find them not as the “dirty” or “strangers” as public propaganda would have one believes about porn … eventually he/one adjusted and normalized into realizing that porn people are just ordinary conscientious people at but another ordinary job albeit one with a negative publicicity to other segments of the population….
SUPERTRAMP LYRICS
“Give A Little Bit”
Give a little bit
Give a little bit of your love to me
Give a little bit
I’ll give a little bit of my love to you
There’s so much that we need to share
Send a smile and show you care
I’ll give a little bit
I’ll give a little bit of my love to you
So give a little bit
Give a little bit of your time to me
See the man with the lonely eyes
Take his hand, you’ll be surprised
Give a little bit
Give a little bit of your love to me
I’ll give a little bit of my love for you
Now’s the time that we need to share
So find yourself [in internet porn or in academic books or wherever whatever: tha?o and husband and two adorable children and Ukraine and midlife crisis temptation song:
But tell me, did you sail across the sun?
Did you make it to the Milky Way to see the lights all faded
And that heaven is overrated?
Tell me, did you fall for a shooting star–
One without a permanent scar?
And did you miss me while you were looking for yourself out there?
Now that she’s back from that soul vacation
Tracing her way through the constellation, hey, hey, hey (mmm)
She checks out Mozart while she does tae-bo
Reminds me that there’s room to grow, hey, hey, hey (yeah)
http://www.azlyrics.com/lyrics/train/dropsofjupiter.html ], we’re on our way back home
Going home
Don’t you need to feel at home? [reversing last time di` ba on telephone in car on way home “tao kho^ng quay la.i {san jose and le^ duye^n II} ddu+o+.c, tao ve^` ga^`n to+’I nha` ro^`I”, we’re on the way to san jose pho+? ba` da^.u co^ng ly’ … “ga^`n to+’i no+i ro^`I” … “are we there yet?” …: song “Everybody’s got a hungry heart/ Lay down your money and you play your part/ Everybody’s got a hungry heart / Everybody needs a place to rest / Everybody wants to have a home / Don’t make no difference what nobody says / Ain’t nobody like to be alone …”]
Oh yeah, we gotta sing
Writer(s): Richard Davies, Roger Hodgson
Copyright: Almo Music Corp., Delicate Music
http://www.azlyrics.com/lyrics/supertramp/givealittlebit.html
…. though one must aim for that conscientious thing if one is to come to that conscientious realization … at any rate an implicit agreement seems to be reached mutually by now 3/2/2014 … as a new generation of porn family and a new generation of the conventional family–Trophy Farm food from JoAnn Fabric ~ trophy wife at “bobo”– from conventional society comes of age …
“Go Your Own Way”
FLEETWOOD MAC LYRICS
[fleetwood: di` ba laughed at ba’c Quy’nh car accident … steve’s father whose house on the hill/mountain top we passed on the way to visit san francisco …]
[Biblical way of gratefulness {e.g. the Lord’s Prayer}: Proverbs 3:6 ESV “In all your ways acknowledge him, and he will make straight your paths. “
Two Sets of Footprints in the sand: http://www.wowzone.com/fprints.htm … arabians at Fabric R’ Us 3/3/2014
Middle Path/Way: “see/hear/say no evil; have eyes/ears/mouths but as though cannot say …”
Lao-Tzu’s Way: “I governed/forced NOT yet everything is governed/forced properly …”
Confucius’ Way: “What Heaven has conferred is called The Nature; an accordance with this nature is called The Path of duty; the regulation of this path is called Instruction. … Let the states of equilibrium and harmony exist in perfection, and a happy order will prevail throughout heaven and earth, and all things will be nourished and flourish.” Doctrine of the Mean
all of these “ways” entail–dduo^i bo` on california and vietnam menus–coverage of all things under heaven and earth–academic and porn, sex and head, etc.–in due proper amounts so that it seems as though you have not but in fact so that you might HAVE–guy saying “I HAVE …”–all things under heaven and earth …: Bette Midler’s song “… from a {Middle Path} distance we all have enough …” .. Post Office mail car and jet came … with application to tha?o and husband and two adorable children: this is the “Goldilock (“bo^’ lock con”, said gia ba?o) and the three bears: not too much not too little but enough” Middle Path “da(‘t di`u nhau va`o dde^’n ca` {cho+’n} mau” agreement that would HAVE but as though HAVE NOT “American Woman” … blond girl russian-ish in appearance in american flag coat at 99 ranch 3/3/2014 ]
Loving you
Isn’t the right thing to do
How can I ever change things that I feel?
If I could
Baby I’d give you my world
How can I
When you won’t take it from me? [for tha?o and husband, ye^’n and thanh so+n: instead of divorce: to HAVE but as though have not …
now I watch the trains rattle on
from the seat of the tractor
….
and you and I don’t talk alot
we don’t really have to
we spent many years
reading each other’s mind
we used up the lightning ………….. there was lightning when it rains but the only thunder was the ones coming from jet planes …
now we don’t bother fighting
such things will happen in time …
there’s a place in her heart for him and place in his heart for her: in ukraine’s heart is a place for russia and a place for europe … in thanh so+n’s heart is a place for gia ba?o and a place for ye^’n … he probably did the le^ duye^n laundry for her day before yesterday 3/4/2014 … in tha?o’s heart is a place for her husband and their two adorable children and similary in her husband’s heart is a place for tha?o and their two adorable children … in academician’s heart is a place for porn actors/actresses and surely in the porn actors/actresses hearts is a place for the academician … people at 99 ranch motion “support both .. head and tail/sex” …
“What A Fool Believes”
THE DOOBIE BROTHERS LYRICS
He came from somewhere back in her long ago
The sentimental fool don’t see
Tryin’ hard to recreate
What had yet to be created once in her life
She musters a smile
For his nostalgic tale
Never coming near what he wanted to say
Only to realize
It never really was
She had a place in his life
He never made her think twice
As he rises to her apology
Anybody else would surely know
He’s watching her go
But what a fool believes he sees
No wise man has the power to reason away
What seems to be
Is always better than nothing
And nothing at all keeps sending him…
Somewhere back in her long ago
Where he can still believe there’s a place in her life
Someday, somewhere, she will return
She had a place in his life
He never made her think twice
As he rises to her apology
Anybody else would surely know
He’s watching her go
But what a fool believes he sees
No wise man has the power to reason away
What seems to be
Is always better than nothing
There’s nothing at all
But what a fool believes he sees…
http://www.azlyrics.com/lyrics/doobiebrothers/whatafoolbelieves.html]
]
You can go your own way
Go your own way
You can call it another lonely day
You can go your own way
Go your own way
[3/2/2014 joann fabric: girl with bountiful boops resembling di` va^n went her own way passed hooters …]
Tell me why
Everything turned around
Packing up
Shacking up’s all you wanna do
If I could
Baby I’d give you my world
Open up
Everything’s waiting for you
A Lover’s Concerto
The Toys
Sandy Lenzer, Denny Randell
NO. 1 FOR 6 WEEKS – 1965
How gentle is the rain
That falls softly on the meadow,
Birds high up the trees
Serenade the flowers with their melodies
Oh, see there beyond the hill,
The bright colors of the rainbow.
Some magic from above
Made this day for us just to fall in love
Now, I belong to you
From this day until forever,
Just love me tenderly
And I’ll give to you every part of me.
Oh, don’t ever make me cry
Through long lonely nights without love.
Be always true to me,
Keep this day in your heart eternally.
Some day we shall return
To this place upon the meadow.
We’ll walk out in the rain,
Hear the birds above singing once again
Oh, you hold me in your arms,
And say once again you love me,
And if your love is true,
Everything will be just as wonderful.
You’ll hold me in your arms,
And say once again you’ll love me,
And if your love is true,
Everything will be just as wonderful.
http://www.barbarastoys.net/lyrics.html
You can go your own way
Go your own way
You can call it another lonely day
You can go your own way
Go your own way
http://www.azlyrics.com/lyrics/fleetwoodmac/goyourownway.html
a monk walking through a house of prostitution would be unaffected provided he has a monk’s sincere heart …

HANOI, Vietnam | Tourists, hawkers and motorcyclists rub shoulders every morning in the congested alleyways of Hanoi’s low-rise Old Quarter, which seems generations away from the office towers and electronics megastores springing up in other parts of the capital. The quarter’s street grid, laid out in the 15th century, is still dominated by dilapidated shops selling everything from brass gongs to bamboo scaffolding.
It is now among Asia’s best-preserved urban hubs of traditional commerce — thanks largely to decades of inattention. The 82-hectare (203-acre) downtown area is crammed with Buddhist temples, pagodas and French colonial shophouses, whose original tiles and peeling yellow paint have become a draw for foreign visitors.
But with property values high, this neighborhood could change dramatically in the coming years as similar ones already have in Singapore, Shanghai and many other cities. Authorities want to begin gentrifying the Old Quarter by relocating 6,200 households between this year and 2020. New construction is likely a few years away, but some residents already have been relocated.
Some of them are nervous, though not necessarily over lost history. They worry about being exiled to the city’s dusty margins, and of being forced to accept a bad deal from a Communist government that has generated public discontent across Vietnam by forcing people off their land with compensation far below market rates.
advertisement on bus in chinatown: matchmaker.com or some such with pictures of what seems to be two Russians a woman and a man kissing …


A woman waits in front of unidentified men in military fatigues blocking a base of the Ukrainian frontier guard unit in Balaklava, Ukraine, on March 1. Ukraine suspects Russia of sending new troops into Crimea and provoking separatist tensions in the region. Crimea is an autonomous republic of Ukraine with an ethnic Russian majority. It’s the last large bastion of opposition to Ukraine’s new political leadership after President Viktor Yanukovych’s ouster.
Simferopol, Ukraine (CNN) — Leaders of a shaky new government in Ukraine were mobilizing troops Sunday amid signs of Russian military intervention in Ukraine’s Crimean peninsula.
….
It was the latest in fast-moving developments that saw Russia’s Parliament sign off on Putin’s request to send military forces into Ukraine, raising the stakes in the escalating [this must have been cause for guest of Dr. OZ to blurt out sounds that resemble “asshole …” in previous notes …] game of brinksmanship.
Putin cited in his request a threat posed to the lives of Russian citizens and military personnel based in southern Crimea. Ukrainian officials have vehemently denied Putin’s claim. CNN crews in and around Crimea’s regional capital of Simferopol, meanwhile, have not seen evidence of a Ukrainian military presence.
Putin’s move prompted world diplomats to call for a de-escalation of tensions that have put the two neighbors on a possible path to war and roiled relations between Russia and the United States.
In what appeared to be an illustration of the growing schism between the two world powers, U.S. President Barack Obama and Putin spoke for 90 minutes — with each expressing their concern over the mounting crisis, according to separate statements released by their respective governments.
According to the Kremlin, Putin told Obama that Russia reserves the right to defend its interests in the Crimea region and the Russian-speaking people who live there.
“President Obama made clear that Russia’s continued violation of Ukraine’s sovereignty and territorial integrity would negatively impact Russia’s standing in the international community,” according to a statement released by the White House.
http://www.cnn.com/2014/03/01/world/europe/ukraine-politics/
from note “nasm and effect of org directive” based on tutorials from http://www.supernovah.com/Tutorials/index.php website by Alex Jorg….
![]()
http://www.supernovah.com/Images/Signature.png ………:
NASM and the effect of changing the ORG directive:
asm.txt:
asm.txt:
[BITS 16]
[ORG 0x0]
jmp 0x0:Start
Start:
cli
mov AX,0x9000
mov SS,AX
mov SP,0xFB00
sti
cli
hlt

listing.txt:
1 [BITS 16]
2 [ORG 0x0]
3
4 00000000 EA[0500]0000 jmp 0x0:Start
5
6 Start:
7 00000005 FA cli
8 00000006 B80090 mov AX,0x9000
9 00000009 8ED0 mov SS,AX
10 0000000B BC00FB mov SP,0xFB00
11 0000000E FB sti
12
13 0000000F FA cli
14 00000010 F4 hlt
15
16 00000011 00<rept> times 510 – ($ – $$) db 0
17 000001FE 55AA dw 0xAA55
ndisasm.txt:
00000000 EA05000000 jmp word 0x0:0x5
00000005 FA cli
00000006 B80090 mov ax,0x9000
00000009 8ED0 mov ss,ax
0000000B BC00FB mov sp,0xfb00
0000000E FB sti
0000000F FA cli
00000010 F4 hlt
*******************************
asm.txt:
[BITS 16]
[ORG 0x7C00]
jmp 0x0:Start
Start:
cli
mov AX,0x9000
mov SS,AX
mov SP,0xFB00
sti
cli
hlt
listing.txt:
1 [BITS 16]
2 [ORG 0x7C00]
3
4 00000000 EA[0500]0000 jmp 0x0:Start
5
6 Start:
7 00000005 FA cli
8 00000006 B80090 mov AX,0x9000
9 00000009 8ED0 mov SS,AX
10 0000000B BC00FB mov SP,0xFB00
11 0000000E FB sti
12
13 0000000F FA cli
14 00000010 F4 hlt
15
16 00000011 00<rept> times 510 – ($ – $$) db 0
17 000001FE 55AA dw 0xAA55
ndisam.txt:
00000000 EA057C0000 jmp word 0x0:0x7c05
00000005 FA cli
00000006 B80090 mov ax,0x9000
00000009 8ED0 mov ss,ax
0000000B BC00FB mov sp,0xfb00
0000000E FB sti
0000000F FA cli
00000010 F4 hlt

Kerry: Russia’s move into Ukraine is ‘incredible act of aggression,’ US eyes repercussions
Kerry: Prepared ‘to go to the hilt’ to isolate Russia
Associated Press
http://start.lenovo.com/news/read/article/ap-obama_putin_starkly_differing_views_on_u-ap

contentment and equilibrium means it doesn’t matter which “choice”–woman picking jewery “apple” off jewelry tree and woman picking time pieces versus colorful feathers at china curios shop … thus also it should not matter whether to^nan stays until summer in california as di` tu+ die^.p invited/requested or goes home to michigan them comes back later … when it does matter then one should contemplate the why and how of it .. the how and why that affect “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well” to the extent that made the choice matters… the same with other types of choices such as political affiliations, country affiliations, etc–is made, the result is the same “muo^n loa`i ddu+o+.c so^’ng la^u bi`nh thu+o+`ng; everyone live long and well” …
ROD STEWART LYRICS
“Forever Young”
May the good Lord be with you
Down every road you roam
And may sunshine and happiness
surround you when you’re far from home
And may you grow to be proud
Dignified and true
And do unto others
As you’d have done to you
Be courageous and be brave
And in my heart you’ll always stay
Forever Young, Forever Young
Forever Young, Forever Young
May good fortune be with you
May your guiding light be strong
Build a stairway to heaven
with a prince or a vagabond
And may you never love in vain
and in my heart you will remain
Forever Young, Forever Young
Forever Young, Forever Young
Forever Young
Forever Young
And when you finally fly away
I’ll be hoping that I served you well
For all the wisdom of a lifetime
No one can ever tell
But whatever road you choose
I’m right behind you, win or lose
Forever Young, Forever Young
Forever Young ,Forever Young
Forever Young, Forever Young
For, Forever Young, Forever Young
Writer(s): Jim Cregan, Bob Dylan
Copyright: Kevin Savigar Music, Special Rider Music, Griffon Investments Limited, Chrysalis Music, Ram’S Horn Music
http://www.azlyrics.com/lyrics/rodstewart/foreveryoung.html






