loops,assembly,counter,increment , Counter not working after jumps - assembly language


Counter not working after jumps - assembly language

Question:

Tag: loops,assembly,counter,increment

For some reason, when i switch to mouse input switch back to keyboard input for my program, increasing and decreasing the counter has no effect. It works perfectly in the first loop where we input characters. Here is the program guys, any advice? look at whatspeed jump for reference after mousetime jump CX counter is not updating or something along those lines. (i do not know if the counter is not updating or weather there is a problem occuring in comparing CX after i switch from mousetime to keytime . )

; You may customize this and other start-up templates; ; The location of this template is c:\emu8086\inc\0_com_template.txt

org 100h

CLEAR MACRO MOV AX,0600H MOV BH,07 MOV CX,0000 MOV DX,184FH INT 10H ENDM

CURSOR MACRO Col, Row MOV AH,02 MOV BH,00 MOV DL,Col MOV DH,Row INT 10H ENDM

DISP MACRO MES MOV AH,09 MOV DX,OFFSET MES INT 21H ENDM

CLEARLINE MACRO ROW CURSOR 00,ROW DISP SPACES

ENDM

ALWAYSONSCREENINFO MACRO CURSOR 16,00 DISP TITLE1 CURSOR 50,00 DISP NAMES1 CURSOR 54,01 DISP NAMES2 CURSOR 33,7 DISP MENU CURSOR 24,9 DISP OPTION1 CURSOR 24,10 DISP OPTION2 CURSOR 22,11 DISP DASHES CURSOR 18,12 DISP MOUSEMENU CURSOR 14,13 DISP OPTION3 CURSOR 8,14 DISP OPTION4 CURSOR 13,15 DISP CHARMENU CURSOR 21,16 DISP KILL ENDM

.MODEL SMALL ; RUN THE PROGRAM IN DIMENSIONS 79x24 .STACK 64H .DATA

TITLE1 DB 'MICROPROCESSOR - EENG410','$' NAMES1 DB 'name1 & name2','$' NAMES2 DB 'std1 std2','$' MENU DB 'MENU','$' OPTION1 DB '1. Press "U" to Speed up the motor','$' OPTION2 DB '2. Press "D" to Slow Down the motor','$' OPTION3 DB '1. Right click the mouse to turn motor direction to clockwise','$' OPTION4 DB '2. Left click the mouse to turn the motor direction to anti-clockwise','$' DASHES DB '----------------------------------------','$' MOUSEMENU DB '(Press M to switch to the mouse options)','$' CHARMENU DB '(Press the scroll button to switch back to fist 2 options)','$' SPEEDUP DB 'DC motor is speeding up ','$' SLOWDOWN DB 'DC motor is slowing down','$' RIGHT DB 'DC motor will now rotate clockwise','$' LEFT DB 'DC motor will now rotate anti-clockwise','$' KILL DB '-----To exit the program, press "E"-----','$' PROGRAMEND1 DB 'Thank you for using our program','$' PROGRAMEND2 DB 'The program has been terminated','$' SPACES DB ' ','$' TRY DB 'Please try again','$' SPEEDNOW DB 'Speed:','$' DIRECTION DB 'Motor Direction:','$' CLOCK DB 'Right','$' COUNTER DB 'Left ','$' N1 DB '1','$'
N2 DB '2','$' N3 DB '3','$' N4 DB '4','$' N5 DB '5','$' N6 DB '6','$' N7 DB '7','$' MAXSPEED DB 'Max speed is 7','$' MINSPEED DB 'Min speed is 1','$'

.CODE MAIN: MOV AX,@DATA MOV DS, AX CLEAR ALWAYSONSCREENINFO

    MOV CX,1
    CURSOR 28,21
    DISP SPEEDNOW
    CURSOR 35,21
    DISP N1
    CURSOR 22,22
    DISP DIRECTION
    CURSOR 39,22
    DISP CLOCK
    MOV CX,1

L0: MOV AH,00 ;LOOP START INT 16H CMP AL,' ' JE SPACED CMP AL,'U' JE FASTER CMP AL,'u' JE FASTER CMP AL,'D' JE SLOWER CMP AL,'d' JE SLOWER CMP AL,'M' JE MOUSETIME CMP AL,'m' JE MOUSETIME CMP AL,'E' JE EXIT CMP AL,'e' JE EXIT JNE TRYAGAINKEY

A1: MOV AX,03 INT 33H CMP BX,0 JE A1 CMP BX,1 ;MOUSE LEFT JE MRIGHT CMP BX,2 ;MOUSE RIGHT JE MLEFT CMP BX,3 JE KEYTIME

SPACED: CLEARLINE 19 JMP L0

FASTER: CLEARLINE 19 CURSOR 27,19 DISP SPEEDUP JMP INCREASE

SLOWER: CLEARLINE 19 CURSOR 27,19 DISP SLOWDOWN JMP DECREASE

MOUSETIME: JMP A1 KEYTIME: JMP L0

MRIGHT: CLEARLINE 19 CURSOR 18,19 DISP RIGHT JMP TRIGHT

MLEFT: CLEARLINE 19 CURSOR 18,19 DISP LEFT JMP TLEFT

TRYAGAINKEY: CLEARLINE 19 CURSOR 28,19 DISP TRY JMP L0

INCREASE: CMP CX,7 JE CANNOTINCREASESPEED INC CX JMP WHATSPEED

DECREASE: CMP CX,1 JE CANNOTDECREASESPEED DEC CX JMP WHATSPEED

TRIGHT: CURSOR 39,22 DISP CLOCK JMP A1

TLEFT: CURSOR 39,22 DISP COUNTER JMP A1

CANNOTINCREASESPEED: CLEARLINE 19 CURSOR 27,19 DISP MAXSPEED JMP L0

CANNOTDECREASESPEED: CLEARLINE 19 CURSOR 27,19 DISP MINSPEED JMP L0

WHATSPEED: CMP CX,1 JE N11 CMP CX,2 JE N22 CMP CX,3 JE N33 CMP CX,4 JE N44 CMP CX,5 JE N55 CMP CX,6 JE N66 CMP CX,7 JE N77

N11: CURSOR 35,21 DISP N1 JMP L0

N22: CURSOR 35,21 DISP N2 JMP L0

N33: CURSOR 35,21 DISP N3 JMP L0

N44: CURSOR 35,21 DISP N4 JMP L0

N55: CURSOR 35,21 DISP N5 JMP L0

N66: CURSOR 35,21 DISP N6 JMP L0

N77: CURSOR 35,21 DISP N7 JMP L0

EXIT: CLEAR CURSOR 21,12 DISP PROGRAMEND1 CURSOR 21,13 DISP PROGRAMEND2 MOV AH, 4CH INT 21H END MAIN

ret


Answer:

The fault is caused because the mouse interrupt 33h function AX=0003h returns the mouse position in CX and DX.

This overwrites your "counter" in register CX.

It is always a dangerous game to keep values in registers throughout a program. Better to have a memory variable location.

You could also try PUSH CX before executing the mouse functions and POP CX after, but your program structure and flow might not be conducive to that (I have not followed it fully).

Also, the reason why your program does not recover from (in your context) the absurd value of CX is because of the test instruction you used. For example here

INCREASE: CMP CX,7
          JE CANNOTINCREASESPEED

you must always be cautious and trap any value that is out of range (even if you think it won't be)

          JGE CANNOTINCREASESPEED

Also with

CANNOTINCREASESPEED: MOV CX,7    ;clamp the value
...

Related:


Get next item in array using iterator using flags


javascript,jquery,loops,iterator,iteration
I am trying to obtain the next object in an object of objects (is you get my drift). I'm looking through the a list of songs, and trying to determine the next song to play. I use the flag playing to check if the song is being played, then i...

IllegalStateException: Iterator already obtained [duplicate]


java,file,loops,path
This question already has an answer here: java.lang.IllegalStateException: Iterator already obtained 1 answer so I wrote a little Java program to test a little stack language I made vie various test file, but for some reason it won't work. Here is the code: import org.apache.commons.io.FilenameUtils; import java.io.IOException; import java.nio.file.*;...

How do I write a loop to read text file and insert it to the database


sql-server,loops,powershell
I'm writing a powershell script to load text files from a specific folder into SQL server database, I have manage to do so but only one file by one file. I want the program to do this automatically once the user inputs the path and the file extension. For example:...

How can i make a jQuery animation loop on infinite, after it finish?


jquery,loops,animation
I have a jQuery animation, i have a flying monkey that has to rotate from left to right and from right to left, is working fine but i have to make the monkey loop. Right now i have improvised, i have made several divs into each other that rotate after...

An error while looping a linear regression


r,loops,data.frame,regression
I would like to run a loop that will run per each category of one of the variables and produce a prediction per each regression so that the sum of the prediction variable will be deduced from the target variable .Here Is my toy data and code: df <- read.table(text...

Counter not working after jumps - assembly language


loops,assembly,counter,increment
For some reason, when i switch to mouse input switch back to keyboard input for my program, increasing and decreasing the counter has no effect. It works perfectly in the first loop where we input characters. Here is the program guys, any advice? look at whatspeed jump for reference after...

How to build a 'for' loop with input$i in R Shiny


r,loops,for-loop,shiny
In my shiny app, I build a a number of checkboxes using a for loop, like this: landelist <- c("Danmark", "Tjekkiet", "Østrig", "Belgien", "Tyskland", "Sverige", "USA", "Norge", "Island") landecheckbox <- c() for (land in landelist){ landechek <- paste0("<label class=\"checkbox inline\"><input id=\"", land, "\" type=\"checkbox\" checked><span>", land, "</span></label>") landecheckbox <- c(landechek,...

How to iterate through a table in its exact order?


loops,for-loop,lua,order
If i try to output this table, they are looped through in the false order: local letters = {DIN1="hi", AIN1= "my", AIN2 ="name", DIN2="is"} for name, value in pairs(letters) do print(name,value) end Expected Output: DIN1 hi AIN1 my AIN2 name DIN2 is Output: AIN1 my DIN2 is DIN1 hi AIN2...

JQuery loop on multiple items of the same CSS class


jquery,loops,each,keyup,word-count
I have multiple fields of the same class. The word count shows up correctly, but changes the value of every word count when one field has received input. Additionally, I'd expect the field to show a word count of 100 if no input exists, but it shows 0. Suggestions on...

NASM: copying a pointer from a register to a buffer in .data


linux,assembly,nasm,x86-64
I am new to asm. I am trying to copy a pointer from a register to a .data variable using NASM, on linux 64-bit. Concider this program: section .data ptr: dq 0 section .text global _start _start: mov [ptr], rsp mov rax, 60 mov rdi, 0 syscall Here I try...

How to match words in 2 list against another string of words without sub-string matching in Python?


python,regex,string,loops,twitter
I have 2 lists with keywords in them: slangNames = [Vikes, Demmies, D, MS Contin] riskNames = [enough, pop, final, stress, trade] i also have a dictionary called overallDict, that contains tweets. The key value pairs are {ID: Tweet text) For eg: {1:"Vikes is not enough for me", 2:"Demmies is...

Using Yahoo! database without quantmod functions


r,loops,yahoo-finance
The problem I am trying to solve is looping a string through R with Yahoo! finance api. This would make a bunch of data frame files, but if I could convert it into xts, that would be awesome. However, the xts part is not as important. library(quantmod) DB <- quantmod:::DDB_Yahoo()...

Macro to push arguments onto stack


visual-c++,assembly,macros
I've been working on a fun little project to mess around with how functions are called and I need a macro to push arguments as it'll be quite time consuming to push the arguments manually for every instance of this obfuscated call. This is my code so far: #define pushargs(...)...

Calling function and passing arguments multiple times


python,function,loops
I want to call the function multiple time and use it's returned argument everytime when it's called. For example: def myfunction(first, second, third): return (first+1,second+1,third+1) 1st call: myfunction(1,2,3) 2nd call is going to be pass returned variables: myfunction(2,3,4) and loop it until defined times. How can I do such loop?...

Error: Junk at EOL, first unrecognised character is '('


assembly,gas,quake
I am trying to compile Quake 1 (QW) from source code and have run into the following problem when compiling client/d_copy.s : Error: Junk at EOL, first unrecognised character is '('. The file in question is here (please excuse the syntax highlighting, pastebin only supports NASM). I am attempting to...

Methods within my while Loop not working


python,loops
I'm making a simple script that looks to see if my favourite YouTuber Casey Neistat has uploaded a new video. I want the script to loop over and over so see if there is a new video or not. However, whenever I run the program it continually says that there...

Understanding NASM Macro


assembly,macros,ffmpeg,nasm
I've come around this macro in a assembly source file and I just can't figure out how it's working. So first I come around this function (hevc_deblock.h): cglobal hevc_v_loop_filter_chroma_8, 3, 5, 7, pix, stride, tc, pix0, r3stride sub pixq, 2 lea r3strideq, [3*strideq] mov pix0q, pixq add pixq, r3strideq TRANSPOSE4x8B_LOAD...

Creating a number list with nested For loops in Python


python,loops,nested
I've been working on this now for well over four hours and i've tried to check several resources. I'm trying to get something like this: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4...

PHP: How to push Select results to multi-dimensional array (partially working)


php,arrays,loops,select,multidimensional-array
I am new to PHP and hope someone can help me with this. I have a Select query that returns (among others) the values from two columns in a db table, "ID" and "en". When getting the results from the Select I would like to store both these values for...

How to innerHTML a function with array as parameter?


javascript,arrays,loops,foreach,innerhtml
I am learning about looping thorugh arrays - I want to pass the result of an if else statement in the forEach function (inside another function with array as parameter) to HTML using innerHTML (does not have to be innerHTML if you know better methods I do not mind). It...

Visual Studios building and debugging .cpp file without main()


c++,assembly,visual-studio-2013
Professor just gave us a block of c++ code in order to learn about the debug windows in Visual Studio, however after creating a blank win32 console project and then dragging in the .cpp file I get the missing .exe error message when attempting to debug. I've looked everywhere and...

ARM assembly cannot use immediate values and ADDS/ADCS together


gcc,assembly,arm,instructions
I am currently trying to speed up some of my C functions on a Cortex-M0 (Freescale KL25Z) using assembly. I get a problem with this minimal test program: @.syntax unified .cpu cortex-m0 .text .global test .code 16 test: mov r0, #0 adds r0, r0, #1 bx lr When I try...

Index out of Range exception in arrays


c#,loops
I am continuously getting out of range exception in my code. I went into the debug mode and found that it was giving an error for the zeroth index itself. Any help would be greatly appreciated. namespace StringTest7 { class Program { static void Main(string[] args) { Input(); StarGenerator(); RemovingWords();...

How to print iterations per second?


python,performance,loops,cmd,progress
I have a small Python script which sends POST requests to a server and gets their response. It iterates 10000 times, and I managed to print the current progress in command prompt using: code=current_requestnumber print('{0}/{1}'.format(str(code),"10000"),end="\r") at the end of each loop. Because this involves interaction with a webserver, I would...

Interface Controls for DoEvent in Excel


excel,vba,excel-vba,loops,doevents
I have a macro to loop through a range and return emails to .Display based on the DoEvents element within my module. I iterate that: row_number = 1 'And Do DoEvents row_number = row_number +1 'Then a bunch of formatting requirements Loop Until row_number = 'some value I am wondering...

Php counting with $i++


php,loops
I have this in a loop: <?php $i = 1; echo '<div id="'.$i.'">' . 'Anchor' . '</div>'; echo '<a href="#'.$i.'">' . 'Link-A ' . '</a>'; echo '<a href="#'.$i.'">' . 'Link-B ' . '</a>'; $i++; ?> This works fine if there is only one object. What do i have to do...

Matlab: Looping through an array


matlab,loops,for-loop,while-loop,do-while
This is my one dimensional array A. containing 10 numbers A = [-8.92100000000000 10.6100000000000 1.33300000000000 ... -2.57400000000000 -4.52700000000000 9.63300000000000 ... 4.26200000000000 16.9580000000000 8.16900000000000 4.75100000000000]; I want the loop to go through like this; (calculating mean interval wise) - Interval length of 2,4,8 (a(1)+a(2))/2 - value stored in one block of...

How to make function in loop run synchronously?


javascript,jquery,loops,google-chrome-extension,synchronization
Am working on a chrome plugin, and need to sendMessage from an 'app page' to a 'content script' and then get the return messages, from inside a loop. But since the loop doesn't wait for the sendMessage to return a value before starting on the next iteration, it is screwing...

How to create series of pandas dataframe by iteration


python,loops,pandas
I want to create df_2008 to df_2014 from an original df by iteration. df has columns names '2008' to '2014' and I want to seperate them into different dfs. I tried for i in range(2008, 2015): 'df_'+str(i)=df[str(i)] Which won't work. I would really appreciate it if anyone could help me....

Python - Using a created list as a parameter


python,list,loops,if-statement,compare
When I run my code it tells me: Type Error: unorderable types: str() < float(). I can't figure out why it won't let me compare these two numbers. The list I am using is defined, and the numbers in it have been redefined as floats, so I'm not sure what...

Matching key/value pairs in two dictionaries and creating a third one


python,loops,dictionary
I have read two files from which I created dictionaries with IDs and their corresponding sequences as keys and values, respectively. I am trying to find the key/value pairs that exist in both dictionaries and to create a new one containing only these matching ones. Each dictionary has a couple...

Infinite loop with fread


c,arrays,loops,malloc,fread
I'm trying to allocate an array 64 bytes in size and then loop over the array indexes to put a read a byte each from the inputfile. but when I don't malloc() the array indexes, the loop stays in index0 (so each time it loops it replaces the content in...

Appending a data frame with for if and else statements or how do put print in dataframe


r,loops,data.frame,append
How do I put what I printed in a dataframe with a for loop and if else statements? Basically, this code: list<-c("10","20","5") for (j in 1:3){ if (list[j] < 8) print("Greater") else print("Less") }) #[1] "Less" #[1] "Less" #[1] "Greater" Or should it be something more like this? f3 <-...

Nested foreach loop in a While loop can make the condition for the while loop go over?


php,loops,foreach,while-loop
Here is a little background on what I am trying to create. I am creating a function called getNextBilling($dateStart,$dateCount = 20) You give it a period length which is the days you want someone to be billed $test->period = '2,5,15'; it takes a starting date which I have assigned on...

Run 3 variables at once in a python for loop.


python,loops,variables,csv,for-loop
For loop with multiple variables in python 2.7. Hello, I am not certain how to go about this, I have a function that goes to a site and downloads a .csv file. It saves the .csv file in a particular format: name_uniqueID_dataType.csv. here is the code import requests name =...

Declaring Variables in the .data Versus on the Stack - ASM


assembly
I'm trying to understand in which cases you would want to declare variables in the .data section of my assembly program and using it for the procedures needed, over instantiating local variables on the stack and vice versa. Is it just that declaring variables in the .data section is only...

Why is my C code printing out an extra line of rows?


c,loops,for-loop,macros,printf
#include <stdio.h> #define rows 500 //can define rows as any number int main() { int i,j; for(i=0;i<=rows;++i) { for(j=0;j<(2*i+1);++j) { printf("* "); } printf("\n"); } return 0; } So here is my code, what it does is it prints the number of rows set by #define and creates a right...

How can I iterate through nested HTML lists without returning the “youngest” children?


javascript,jquery,html,list,loops
Fiddle: https://jsfiddle.net/zayjeLrk/12/ I want to iterate through an HTML nested list that is 3-layers deep. <ul> <li>animals <ul> <li>birds <ul> <li>crow</li> <li>parrot</li> </ul> </li> <li>reptiles</li> </ul> </li> <li>plants</li> <li>bugs</li> </ul> I want it to iterate through the list so that it returns the elements in this order (note, this isn't...

Add mouseListener to Labels in Array Loop


java,loops,mouselistener
I want to add mouseListener to all labels in the array. Every label should show an other card of the layout. If I use below code, all labels show card6. What is wrong? sorry this is correct code.. panList = new JPanel(); panList.setBounds(0, 0, 206, 517); panList.setLayout(null); cs.add(panList); CreateCards(); int...

2 Foreach Loop Inside A Table


php,loops,laravel-4,foreach,blade
I had Users table and group table, when i load a group table, it loads the user which have same group_id as the group table id. it works, but my problem is the foreach was quite a mess. the output looks like this.. however, i want to make the output...

performance issues executing list of stored procedures


c#,multithreading,performance,loops
I'm having some performance issues when starting my windows service, the first round my lstSps is long (about 130 stored procedures). Is there anyway to speed this up (except for speeding the stored procedures up)? When the foreach is over and goes over to the second round it goes faster,...

assembly function with C segfault


c,assembly,x86,sse,fpu
I am trying to make assembly function that uses SSE and FPU for parallel calculations. Unfortunately I am receiving segmentation fault(core dumped) error(while debugging it doesn't show in assembly function). I also cannot step out from assembly function. Gdb shows: Warning: Cannot insert breakpoint 0. Cannot access memory at address...

Escape out of 2 Javascript loops (or stop script)


javascript,loops
I have a quiz on my site that will submit if the time is up. After the form submits (via jquery), I would like the timer to stop working. I tried putting return: false after the test submits, but that didn't work. html: <span id="time">30:00</span> javascript: var thirtyMinutes = 60...

How to repeat this statement in R probably using apply()


r,loops
It might seem a silly question but how to repeat this line for 152 times and I would not like to use a for loop,since later it will not be efficient with larger data sets: reviews = as.vector(t(mydata)[,1]) mydata is a row in a data.frame and reviews is an array...

for each loop: how to step out of conditions


loops,vbscript,condition
I am stuck at creating a loop for testing filenames with VBScript. To be precise, I am trying to perform something like a jump in a For Each loop. The loop should test all files in a folder and in some cases it should delete some files. But while running,...

Comparing two values in the same row and change if needed


php,mysql,loops
Im trying to compare two values in the same record and if $minvoorraad > $voorraad , set $voorraad = $minvooraad. Database(cropped picture): This is what i have now but it changes all numbers to same <?php session_start(); include 'connect.php'; $sql = "SELECT Minvoorraad, Voorraad FROM product"; $query = mysqli_query($con, $sql);...

storing array from user and accessing it


arrays,assembly,input,user,mips
I have to create an int array based on user input, sum the integers, and output the sum and the array itself. My code calculates the sum correctly, but I cannot output the list. It only prints out the last number and zeros and then gets stuck in an infinite...

echo both users


php,mysql,sql,database,loops
The code at the bottom of this post currently echoes: Name: Spongebob Squarepants Description: I live in a pineapple under the sea. Role: editor But there are two users in "wp_usermeta". It's only echoing one. The result needs to look like this: Name: wp_dev_05 Description: My name is Chris Topher!...

Javascript: Forloop Difference between i++ and (i+1)


javascript,loops,for-loop
I was building a javascript for loop and I want to compare the value of an array to the next value in the array. If both values are not equal, I want to return true, otherwise I want to return false. In the code below I pass the string "aba",...