x86-16

Understanding of boot loader assembly code and memory locations

谁说我不能喝 提交于 2019-12-22 12:30:11
问题 I want to check my understanding of the following bootloader code: BITS 16 start: mov ax, 07C0h ; Set up 4K stack space after this bootloader add ax, 288 ; (4096 + 512) / 16 bytes per paragraph mov ss, ax mov sp, 4096 mov ax, 07C0h ; Set data segment to where we're loaded mov ds, ax mov si, text_string ; Put string position into SI call print_string ; Call our string-printing routine jmp $ ; Jump here - infinite loop! text_string db 'This is my cool new OS!', 0 print_string: ; Routine: output

Stack Overflow of 8086 microprocessor

自古美人都是妖i 提交于 2019-12-22 09:55:52
问题 What'll be the behaviour of the 8086 Microprocessor when the stack is full and even then I push something into it? 回答1: On the 8086, a PUSH instruction or implicit stack push will decrement the SP register by two and store the appropriate quantity at SS:SP (i.e. 16*SS+SP). If the SP register was $0000, the data will go to SS:$FFFE. If the SP register was $0001, the MSB of the data will go to SS:$0000 and the LSB will go to SS:$FFFF. The processor will not take any special notice of the stack

Explain how the AF flag works in an x86 instructions?

大兔子大兔子 提交于 2019-12-21 12:21:31
问题 I have a little 8086 emulator and I've had a long standing bug for like 2 years now that AF does not behave properly inside of sub and add instructions. My current way of computing its value is this for 8 bit numbers and subtraction: uint8_t base=... , subt=... base=base&0xF; subt=subt&0xF; //isolate bottom nibble if((int16_t)base-subt>7 || (int16_t)base-subt<-7){ flags.af=1; }else{ flags.af=0; } (assuming an instruction like sub base,subt ) And for adding it's like this: uint8_t base=... ,

Assembly 8086 - copy one buffer to another

为君一笑 提交于 2019-12-21 06:30:58
问题 im working on a assembly program that reads the whole text file into a buffer then displays it in the console. It displays 24 lines (each line has a max lenght of 80, because im using a 80 wide * 25 height dossbox ) at once then waits for user input so the user can scroll through the text. I wanted to add the number of line to the beginning of each line, so figured i could make a second buffer and copy chars 1by1 from the first one and when i find a newline i would call a procedure which

Assembly 8086 - copy one buffer to another

主宰稳场 提交于 2019-12-21 06:29:31
问题 im working on a assembly program that reads the whole text file into a buffer then displays it in the console. It displays 24 lines (each line has a max lenght of 80, because im using a 80 wide * 25 height dossbox ) at once then waits for user input so the user can scroll through the text. I wanted to add the number of line to the beginning of each line, so figured i could make a second buffer and copy chars 1by1 from the first one and when i find a newline i would call a procedure which

Assembly code skipping a line?

一个人想着一个人 提交于 2019-12-20 07:51:41
问题 Why is my assembly code skipping a line? It keeps skipping the line mov AX,A org 100h count equ 2 A DW 5 B DW 6 Y0 DW ? Y1 DW ? mov AX,A add AX,B sub AX,count mov Y0,AX mov BX,B neg BX add BX,count mov Y1,BX ret 回答1: Let's see what code bytes these instruction mnemonics would assemble to: org 100h count equ 2 05 00 A DW 5 06 00 B DW 6 00 00 Y0 DW ? 00 00 Y1 DW ? A1 00 01 mov AX,A ;NASM "mov ax, [A]" 03 06 02 01 add AX,B ;NASM "add ax, [B]" 83 E8 02 sub AX,count ... The code bytes are on the

Override default INT 9h

我的梦境 提交于 2019-12-20 07:38:36
问题 I'm trying to override the default interruption when a key is pressed. Here is my code : I don't understand why it doesn't work, it works with others INT numbers (43h for example) mov al,9h mov ah,25h mov bx,seg int9h mov ds,bx mov dx,offset int9h int 21h (Where int9h is a label in my code) Does anyone know how to hook the interruption when a key is pressed ? Thanks ! EDIT: mov ax,2509h mov dx,offset int9h int 21h int9h PROC ;do some stuff IRET int9h ENDP 回答1: I'll try and answer this again -

MOV 8 bit to 16 bit register (al to bx)

你。 提交于 2019-12-20 05:46:08
问题 How can I fix the problem of moving 8 bit value to the BX register (16 bit)? mov al, 10h mov bx, al for this I get: operands do not match: 16 bit and 8 bit register 回答1: The answer depends on whether you want to zero extend or sign extend the value and on whether you can or cannot use instructions available starting with the 80386. For better performance, the 80386 or later code should be used if movzx and movsx are available. zero extend on an 8086 or 80286 Zero the upper half, then move to

Code executes condition wrong?

拟墨画扇 提交于 2019-12-20 02:54:26
问题 Basic question here, I wrote the following block: IDEAL MODEL small STACK 100h DATASEG Var1 db 4 Var2 db 2 CODESEG start: mov ax, @data mov ds, ax xor ax, ax mov al, [Var1] cmp al, [Var2] jg Var1Greater mov ax, 1 Var1Greater: mov ax, 0 I'm new to assembly. I wanted to create a code that compares [Var1] to [Var2]. IF(!) [Var1] is greater than [Var2], execute mov ax, 1 . IF(1) anything else(equal or less) excecute, mov ax, 0 . How can this be done? the code I wrote executes both instructions if

Assembly text colors

天涯浪子 提交于 2019-12-20 01:45:23
问题 I'm doing an iso file in assembly and I want to add color to the text (in this case: red). Does anyone know how to do it? [BITS 16] [ORG 0x7C00] jmp main main: mov si, string ; si=string call printstr jmp $ printstr: lodsb ; al=&si[0] cmp al,0 ;FLAGS = 0 jnz print ret print: mov ah,0Eh int 10h jmp printstr string db "HELLO WORLD!",13,10,0 times 510 - ($-$$) db 0 dw 0xAA55 回答1: As a preliminary advice, always setup the segment registers that your bootloader depends on. Here, because of lodsb