问题
Im very new in this assembly language can you guys help me
.model small
.stack
.code
org 100h
start:
main proc
mov cx,1; how many times to loop
here:mov al,00000001b
mov dx,378h
out dx,al
call delay
mov al,00000010b
mov dx,378h
out dx,al
call delay
mov al,00000100b
mov dx,378h
out dx,al
call delay
mov al,00001000b
mov dx,378h
out dx,al
call delay
mov al,00010000b
mov dx,378h
out dx,al
call delay
mov al,00100000b
mov dx,378h
out dx,al
call delay
mov al,01000000b
mov dx,378h
out dx,al
call delay
mov al,10000000b
mov dx,378h
out dx,al
call delay
loop here
int 20h
main endp
delay proc
push cx
mov cx,2050
delay2:
push cx
mov cx,10000
delay3:
nop
nop
nop
nop
nop
loop delay3
pop cx
loop delay2
pop ax
ret
delay endp
end start
this is my code
回答1:
Since you are writing to port 0x378, I am guessing you have eight LED's, one each attached to eight data pins and eight ground pins on your PARALLEL PORT. This tells me you have an older machine and probably are running TRUE DOS. Is this correct? (If so, be very careful of the current being drawn from the LEDs that you don't damage your parallel port. A current limiting resister is highly recommended.)
You are using the Small model, which is designed to create a .OBJ file for a linker to create an .EXE file. However, you then place the ORG 100h directive which is designed to create a .OBJ file for a linker to create an .COM file, or create it directly without the linker.
If you are creating an .EXE and running this .EXE, yes, you will get an illegal instruction at some point in time, with the way you have coded this (labels will be 100h bytes away from where they should be).
If you aren't already, you need to convert the .EXE to a .COM file. The .EXE extension (along with a signature) will tell the OS to load a stack, data, and code segment. The .COM extension (with the missing signature) will tell the OS to simply load the binary file and jump to offset 100h, period.
- Change the .model to 'tiny' (as apposed to 'small'), telling the assembler to create a .COM file, or use a tool to convert the .EXE to a .COM.
- Remove the 'main proc' and 'main endp' lines. They are not needed in this context.
- For better readability, put all labels ('start', 'here', 'delay', etc.) in the first column. i.e.: no spaces before the name.
- Since your delay routine does not modify the DX register, there is no need to keep reassigning it the same value each time. If the delay routine modifies this register, you can preserve it by pushing/popping it within the procedure.
- Since you are running this in DOS, you can read the dword at physical address 0x0046C as an incremental timer. This is the DOS time of day tick and is incremented 18.2 times a second. Simply read that value, wait for it to change a certain count of times, and you have a simple delay routine.
To read that value, you will have to set up a segment register and a base/index register to point to that physical address. If you don't know what I mean, you will need to read about 16-bit segmented addressing.
来源:https://stackoverflow.com/questions/59126475/tasm-running-led-animation-with-specific-time-of-stop