ORG isn't a variable its an assembler directive.
The command ORG is the ORiGinate command which sets the start of the assembled code. ORG 100h means originate this block of assembled code at the location 100 hexidecmal.
Note: the Origin point of the code block does not HAVE to be the execute point in asssembly language. Therefore you could ORG at 100 hex and exec the code at 150 Hex.
org 100h L2: mov bh,x(si) mov ah, x(si) L1: cmp si,7 je L inc si cmp ah, x(si) jg L1 jl L2 L:ret x db 1,3,7,8,6,9,5
name "str2bin" ; convert string number to binary! ; this program written in 8086 assembly language to ; convert string value to binary form. ; this example is copied with major modifications ; from macro "scan_num" taken from c:\emu8086\inc\emu8086.inc ; ; the original "scan_num" not only converts the string number ; but also reads the string from the keyboard and supports ; backspace key, this example is a shorten version ; of original "scan_num" macro. ; here we assume that the string number is already given, ; and the string number does not contain non-digit chars ; and it cannot cause buffer overflow (number is in word range ; and/or has only 4 digits). ; negative values are allowed in this example. ; the original "scan_num" does not allow to enter non-digits ; and it also checks for buffer overflow. ; you can the original file with other macro definitions ; in c:\emu8086\inc\emu8086.inc org 100h jmp start ; text data: msg1 db 0Dh,0Ah, " enter any number from -32768 to 65535 inclusive, or zero to stop: $" msg2 db 0Dh,0Ah, " binary form: $" ; buffer for int 21h/0ah ; fist byte is buffer size, ; second byte is number of chars actually read (set by int 21h/0ah). buffer db 7,?, 5 dup (0), 0, 0 ; for result: binary dw ? start: ; print welcome message: mov dx, offset msg1
There should be a jump over the variables/array declaration:org 100hjmp codemyArray dw 2, 12, 8, 52, 108code: mov si, 0mov ax, myArray[si]retFor the computer all bytes look the same, it cannot determine if it's an instruction or a variable. Here is an example of MOV AL, 5 instruction that can be coded with simple variable declarations:org 100hbyte1 db 176byte2 db 5retWhen you run this program in emulator you can see that bytes 176 and 5 are actually assembled into:MOV AL, 5This is very typical for Von Neumann Architecture to keep data and instructions in the same memory, It's even possible to write complete program by using only DB (define byte) directive.org 100hdb 235 ; jump...db 6 ; 6 - six bytes forward (need to skip characters)db 72 ; ascii code of 'H'db 101 ; ascii code of 'e'db 108 ; ascii code of 'l'db 108 ; ascii code of 'l'db 111 ; ascii code of 'o'db 36 ; ascii code of '$' - DOS function prints until dollar.db 186 ; mov DX, .... - DX is word = two bytesdb 2 ; 02 - little enddb 1 ; 01 - big enddb 180 ; mov AH, ....db 9 ; 09db 205 ; int ...db 33 ; 21h - 33 is 21h (hexadecimal)db 195 ; ret - stop the program.8086 and all other Intel's microprocessors store the least significant byte at a lower address. 102h is the address of 'H' character = org 100h + 2 bytes (jmp instruction). The above assembly code produces identical machine code to this little program:org 100hjmp codemsg db 'Hello$'code: mov DX, offset msgmov AH, 9int 21hretIf you open the produced ".com" file in any hex editor you can see hexadecimal values, every byte takes two hexadecimal digits, for example 235 = EB, etc... memory window of the emulator shows both hexadecimal and decimal values.
org 100h .data str1 db "Computer" str2 db "computer" mes1 db "string are same $" mes2 db "string are different $" .code assume cs:code,ds:data start: mov ax,@data mov ds,ax mov es,ax mov si,offset str1 mov di,offset str2 cld mov cx,8 repe cmpsb mov ah,9 jz skip lea dx,mes2 jmp over skip: lea dx,mes1 over: int 21h mov ax,4c00h int 21h end start ret
; count_chars.asm ; counts the number of characters of a zero terminated string. name "counter" org 100h jmp start str1 db 'abcdefg hijklmnop qrstvuwxyz', 0 start: lea bx, str1 ; load address of string. mov ax, 0 ; reset counter. compare: cmp [bx], 0 ; is it end of string? je done ; if zero, then it's the end. inc ax ; count char. inc bx ; next memory position in string. jmp compare ; print result in binary: done: mov bx, ax mov cx, 8 print: mov ah, 2 ; print function. mov dl, '0' test bl, 10000000b ; test first bit. jz zero mov dl, '1' zero: int 21h shl bl, 1 loop print ; print binary suffix: mov dl, 'b' int 21h ; wait for any key press.... mov ah, 0 int 16h ret ; ; count_chars.asm ; counts the number of characters of a zero terminated string. name "counter" org 100h jmp start str1 db 'abcdefg hijklmnop qrstvuwxyz', 0 start: lea bx, str1 ; load address of string. mov ax, 0 ; reset counter. compare: cmp [bx], 0 ; is it end of string? je done ; if zero, then it's the end. inc ax ; count char. inc bx ; next memory position in string. jmp compare ; print result in binary: done: mov bx, ax mov cx, 8 print: mov ah, 2 ; print function. mov dl, '0' test bl, 10000000b ; test first bit. jz zero mov dl, '1' zero: int 21h shl bl, 1 loop print ; print binary suffix: mov dl, 'b' int 21h ; wait for any key press.... mov ah, 0 int 16h ret ;
org 100h L2: mov bh,x(si) mov ah, x(si) L1: cmp si,7 je L inc si cmp ah, x(si) jg L1 jl L2 L:ret x db 1,3,7,8,6,9,5
25 to 1
Manchester united vs Stoke: 15 November 2008, at Old Trafford in the Premier league Man utd won 5-0
name "str2bin" ; convert string number to binary! ; this program written in 8086 assembly language to ; convert string value to binary form. ; this example is copied with major modifications ; from macro "scan_num" taken from c:\emu8086\inc\emu8086.inc ; ; the original "scan_num" not only converts the string number ; but also reads the string from the keyboard and supports ; backspace key, this example is a shorten version ; of original "scan_num" macro. ; here we assume that the string number is already given, ; and the string number does not contain non-digit chars ; and it cannot cause buffer overflow (number is in word range ; and/or has only 4 digits). ; negative values are allowed in this example. ; the original "scan_num" does not allow to enter non-digits ; and it also checks for buffer overflow. ; you can the original file with other macro definitions ; in c:\emu8086\inc\emu8086.inc org 100h jmp start ; text data: msg1 db 0Dh,0Ah, " enter any number from -32768 to 65535 inclusive, or zero to stop: $" msg2 db 0Dh,0Ah, " binary form: $" ; buffer for int 21h/0ah ; fist byte is buffer size, ; second byte is number of chars actually read (set by int 21h/0ah). buffer db 7,?, 5 dup (0), 0, 0 ; for result: binary dw ? start: ; print welcome message: mov dx, offset msg1
MUL PROC NEAR MUL1: MOV AL,SI MOV BL,DI MUL BL MOV BL,100H DIV BL .ENDP BY Haseeb Khan :)
Program: include "emu8086.inc" ORG 100h MOV AX, 0004H //Move 1st 16-bit number to AX. MOV BX, FFFEH //Move 2nd 16-bit number to BX. IMUL BX //Multiply BX with AX and the result will be in DX:AX. CALL PRINT_NUM //Print the result. RET //Return. DEFINE_PRINT_NUM //Declare function. END
INT 21h / AH= 3Ch - create or truncate file.entry:CX = file attributes: mov cx, 0 ; normal - no attributes. mov cx, 1 ; read-only. mov cx, 2 ; hidden. mov cx, 4 ; system mov cx, 7 ; hidden, system and read-only! mov cx, 16 ; archiveDS:DX -> ASCIZ filename.returns:CF clear if successful, AX = file handle.CF set on error AX = error code.note: if specified file exists it is deleted without a warning.example: org 100h mov ah, 3ch mov cx, 0 mov dx, offset filename mov ah, 3ch int 21h jc err mov handle, ax jmp k filename db "myfile.txt", 0 handle dw ? err: ; .... k: ret
[org 0x0100] mov ax,6 ; load first number in ax add ax,6 ; accumulate sum add ax,6 add ax,6 add ax,6 add ax,6 mov ax, 0x4c00 ; terminate program int 0x21 ------ Another way: [org 0x0100] ; This is a .com file, not an .exe. DOS .com files start at 100h (256 decimal), have no stack segment, are no larger than 64k, and the code and data segments must be the same. xor ax, ax ;zero register mov cx, 6 ;put 6 in counter register for loop instruction start: add ax,6 ; accumulate sum loop start ; decrements cx and serves as conditional jump to start label. mov ax, 0x4c00 ; terminate program int 0x21 (I rarely terminated DOS programs this way using the DOS termination service (int 21h, ah=4ch). Usually, terminating with RetN was enough.)
Data Segment string 1 db 'This is source $' string2 db 15 dup() Data Ends Assume cs:code, ds:data org 100h Code segment Mov AX, data Mov DS, AX Mov si, offset string1 Mov di, offset string2 Mov CX, 0015 MOVSB Mov AX, 004ch Int 21h Code Ends End
There should be a jump over the variables/array declaration:org 100hjmp codemyArray dw 2, 12, 8, 52, 108code: mov si, 0mov ax, myArray[si]retFor the computer all bytes look the same, it cannot determine if it's an instruction or a variable. Here is an example of MOV AL, 5 instruction that can be coded with simple variable declarations:org 100hbyte1 db 176byte2 db 5retWhen you run this program in emulator you can see that bytes 176 and 5 are actually assembled into:MOV AL, 5This is very typical for Von Neumann Architecture to keep data and instructions in the same memory, It's even possible to write complete program by using only DB (define byte) directive.org 100hdb 235 ; jump...db 6 ; 6 - six bytes forward (need to skip characters)db 72 ; ascii code of 'H'db 101 ; ascii code of 'e'db 108 ; ascii code of 'l'db 108 ; ascii code of 'l'db 111 ; ascii code of 'o'db 36 ; ascii code of '$' - DOS function prints until dollar.db 186 ; mov DX, .... - DX is word = two bytesdb 2 ; 02 - little enddb 1 ; 01 - big enddb 180 ; mov AH, ....db 9 ; 09db 205 ; int ...db 33 ; 21h - 33 is 21h (hexadecimal)db 195 ; ret - stop the program.8086 and all other Intel's microprocessors store the least significant byte at a lower address. 102h is the address of 'H' character = org 100h + 2 bytes (jmp instruction). The above assembly code produces identical machine code to this little program:org 100hjmp codemsg db 'Hello$'code: mov DX, offset msgmov AH, 9int 21hretIf you open the produced ".com" file in any hex editor you can see hexadecimal values, every byte takes two hexadecimal digits, for example 235 = EB, etc... memory window of the emulator shows both hexadecimal and decimal values.
; This may not be what you wnat in that it displays in Decimal but, it should ; get you started. It was writtne in x86 Assembly using emu8086. Bruce name Powers ; author: Bruce Hesher ; ; View the flags register, Variables, and the Stack while running ; this program. ; AX - used to store sum ; BX - used to count the number of time the subroutine loops ; CX - used by scan_num to store value ; DX - used to return value ; org 100h ; Create COM file include 'emu8086.inc' ; emu8086.inc has some useful subroutines. ; prompt user for the number of Fibonacci numbers to display. mov ah, 9 mov dx, offset msg_prompt int 21h call scan_num ; Type digits then ENTER, result goes in CX lea si, msg_CRLFLF ; 1 CR and 2 LF call print_string lea si, space ; Used PRINT_STRING inside the program loop. mov ax, 0 ; Clear AX. mov al, cl ; Seed AL with number to show powers of. mov [value], cx ; mov number to value since CX used by loop mov cx, 20 NEXT: mul [value] ; (DX AX) = AX * operand. call print_num_uns ; print value in AX call print_string loop NEXT ; jump if no overflow to next ret ; to OS ; Define variables msg_prompt db 'Enter the number to calc the powers of: $' msg_CRLFLF db 0Dh, 0Ah, 0Ah space dw 20h value dd 0h ; dd directive to define double length word (4bytes). ; Define selected subroutines from emu8086.inc DEFINE_SCAN_NUM DEFINE_PRINT_STRING DEFINE_PRINT_NUM_UNS ; Print unsigned number in AX END ; directive to stop the assembler.
org 100h .data str1 db "Computer" str2 db "computer" mes1 db "string are same $" mes2 db "string are different $" .code assume cs:code,ds:data start: mov ax,@data mov ds,ax mov es,ax mov si,offset str1 mov di,offset str2 cld mov cx,8 repe cmpsb mov ah,9 jz skip lea dx,mes2 jmp over skip: lea dx,mes1 over: int 21h mov ax,4c00h int 21h end start ret