x86-16

Why won't the program print the sum of the array?

▼魔方 西西 提交于 2019-12-02 02:31:55
So I'm building a simple 8086 Assembly program that allows the user to input 4 digits, store them in an array and print out the sum of those digits (The sum must be a one digit number): data segment i db ? array db 20 dup(?) sum db ? ends stack segment dw 128 dup(0) ends code segment mov ax, data mov ds, ax mov es, ax mov i, 0 Enter: mov ah, 1 int 21h mov bl, i mov bh, 0 mov array[bx], al inc i cmp i, 4 jne Enter mov sum, 0 mov i, 0 Calc: mov bl, i mov bh, 0 mov al, array[bx] add sum, al inc i cmp i, 4 jne Calc mov dl, sum mov ah, 2 int 21h mov ax, 4c00h int 21h ends However when I input the

Why am I getting zero from mov ax, bx+si+1?

做~自己de王妃 提交于 2019-12-02 02:23:51
问题 mov ax,10 mov bx,4 mov si,ax mov ax,bx+si+1 LEA ax,[bx+si+1] When I add bx,si and 1 together and move to ax , the result is 0. At the next line, when I use LEA it works and I get 15. Why am I getting zero when using move? 回答1: Your question is : "Why am I getting zero from mov ax, bx+si+1?". It's hard to give you an accurate answer because you forgot to tell what compiler you are using and your code snippet doesn't include the data segment so we can't see your data. What we can do is to test

Assigning value to the variable present in previous line using $ sign

只愿长相守 提交于 2019-12-02 01:33:20
I'm trying to understand the MS-DOS v2.0 source code , and in particular some of the code in MSDATA.ASM . This code was originally assembled with a 35+ year old MASM assembler (a version that wasn't commercially available). The code I'm interested in is near the beginning: SUBTTL Initialized data and data used at DOS initialization PAGE ; DATA AREA for MS-DOS IFNDEF KANJI KANJI EQU 0 ;FALSE ENDIF CONSTANTS SEGMENT BYTE PUBLIC 'CONST' EXTRN international_table:BYTE EXTRN Current_Country:WORD ORG 0 CONSTRT EQU $ ; Start of constants segment PUBLIC DevStrLen DEVSTRLEN DB 3 ; Size of below PUBLIC

Get the supported “bitness” of an x86 CPU when booted in 16-bit mode

筅森魡賤 提交于 2019-12-02 00:56:11
I am developing an x86 bootloader and have come across this problem (which I guess should be pretty straightforward, but so far I haven't been able to solve): I want to detect the bitness of the CPU host (e.g. if it's 16bit-only, or supports 32bit or 64bit). I have used the CPUID instruction, but it was introduced with 486 so doesn't help for detecting 16-bit-only vs. a 386-compatible CPU that supports 32-bit protected mode (or 32-bit operand-size in real mode with prefixes). Checking for 32-bits (see http://www.rcollins.org/ddj/Sep96/Sep96.html ): 16-bit CPUs without protected mode (8088/8086

Looping statement that works in Windows 7 debug instructions won't work in DOSBox 0.74

末鹿安然 提交于 2019-12-02 00:49:39
We had an activity about looping in assembly language. Our task is simple: display the numbers 0 to 9 with spaces in-between each number. I got the code to work in the command prompt using the 'debug' command in WINDOWS 7 in our school. My laptop is Windows 10 and I recently found out that there's no 'debug' command in the command prompt. So I tried writing my code in DOSBox 0.74 (latest, maybe). Every time i run it in DOSBox, the programs suddenly hangs up and then crashes. Here's the code mov cx,0a mov ah,02 mov dl,30 int 21 mov bl,dl mov dl,20 int 21 mov dl,bl inc dl loop 0107 int 20 Can

shifting a binary number to the right in assembly with SAR vs. SHR

可紊 提交于 2019-12-02 00:42:09
问题 We know that when we shift a binary number to the right, it is divided by 2. For the number: 1001 0001 . Let's assume that is stored in AX register: If we consider it as unsigned number (which is equal to 145 in decimal): SHR AX, 1 will make AX equal to 0100 1000 which is equal to 72 in decimal, and this is right. But if we consider it as signed number (which is equal to -111 in decimal): SAR AX, 1 will make AX equal to 1100 0100 which is equal to -56 in decimal, and this is wrong because it

INT 13, 2 hanging on x86 real mode when trying to read sectors from floppy drive

好久不见. 提交于 2019-12-02 00:21:44
问题 I'm writing a DOS clone for a school project and I'm trying to read some sectors from a floppy drive (mainly the root directory of a FAT12 file system, sector 19) using BIOS INT 13, 2. I set the parameters right - or at least I think I do so - and then call INT 0x13 with AH = 2. Then, though, the system hangs. I can't figure why. I'm using the following code to call the interrupt: mov ah, 0x2 ;Read sectors function mov al, 1 ;I want to read one sector mov ch, 0 ;From track 0 mov cl, 2 ;Sector

Calculate Segment:Offset from absolute address

不羁岁月 提交于 2019-12-01 23:52:26
I can calculate an address Segment:Offset as Segment * 0x10 + Offset . But how do I calculate the opposite? E.g. how do I get from 0xF4170 to F400:0170 and from 0xACF04 to ABCD:1234 ? Necrolis You would be required to have either the base or the offset to start with, along with the linear address, as multiple Segment:Offset pairs can map to the same linear address. so if we have the segment 0xF400 and the linear address 0xF4170 , we get the offset being 0xF4170 - (0xF400 << 4) which is 0x170 . Doing this with only knowing the linear address doesn't have a unique solution, so you have to choose

Unable to keep a square a full square while moving it

僤鯓⒐⒋嵵緔 提交于 2019-12-01 22:54:09
I have been trying to draw a box in assembly and move it horizontally across the screen. The code of printing the square itself works for me but when I try to make it move it is not working very well. I can see it moving but not as a full square, if you get my point. My code: in Assembly Tasm STA SEGMENT STACK DB 0FFFeH DUP(?) STA ENDS DATA SEGMENT ;----------- ;VARIABLES HERE xpos dw 50h ypos dw 50h color db 9h constat equ 0ffffh siNum dw ? diNum dw ? numOFtime dw 0h ;------------- DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STA START : MOV AX,DATA MOV DS,AX ;start coding here: mov ah, 0

Assembly text colors

瘦欲@ 提交于 2019-12-01 19:32:26
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 As a preliminary advice, always setup the segment registers that your bootloader depends on. Here, because of lodsb together with [ORG 0x7C00] , you must set DS=0 . Best also make sure the direction flag DF is in a known