Assembly language-branching program

这是一个使用8086汇编语言编写的字符加密程序,用户通过键盘输入一个字符,程序按照特定算法进行加密:数字加密循环加3,字母加密循环加5。非数字非字母字符保持不变。加密后的字符会显示在屏幕上,并询问用户是否继续。程序直到用户输入'#'才结束。

Assembly language-branching program

题目

编写一个单字符加密程序,程序从键盘输入一个字符,经过加密后显示输出。加密 算法为:数字密文=原文循环加3,字母密文=原文循环加5。即0->31->4…7->08->19 既不是数字也不是学母的字符按原样输中。

Tool:

emu8086

Structure:

program:

DATA SEGMENT ;SEGMENT是分段的逻辑标志
    str1 DB "PLEASE INPUT A NUMBER 0-9 OR A CHAR:$"
    str2 DB "OUTPUT:$"
    str3 DB "IF YOU WANT CONTINUE PLEASE ENTER THE #:$ "
    str4 DB "THIS PROGRAM IS OVER,THANKS:$"
    input DB '0'
    output DB '0'
    A DB '0'
DATA ENDS  ;SEGMENT以ENDS结束

CODE SEGMENT ;代码段
    ASSUME CS:CODE,DS:DATA ; 伪指令,告诉编译器段寄存器和段名之间的关系

START: 
        MOV AX,DATA
        MOV DS,AX
        
BEGIN:
        LEA DX,str1 ;输出字符串1
        MOV AH,9
        INT 21H
        
        MOV AH,1  ;从键盘输入一个字符
        INT 21H
        MOV BL,AL  ; 将接收到的字符转到BL寄存器中
        
        MOV DL,0DH  ;回车
        MOV AH,02H
        INT 21H
        MOV DL,0AH  ;换行
        MOV AH,02H
        INT 21H

        LEA DX,str2  ;输出字符串2
        MOV AH,9
        INT 21H
        
        MOV input,BL  ;赋值给input
        CMP input,'0' ;与0比较
        JL L
        CMP input,'9' ;与9比较
        JLE L1
        CMP input,40H
        JL L
        CMP input,'Z'
        JLE L2
        CMP input,60H
        JL L
        CMP input,'z'
        JLE L3

L:     ;L1标志,直接输出BL寄存器的值
        MOV output,BL
        MOV DL,output
        MOV AH,02H
        INT 21H     

L1:     ;L11标志,输出加密结果
        MOV BL,input
        ADD BL,03H
        MOV A,BL
        CMP A,'9' ;与9比较
        JG L11
        MOV output,BL
        MOV DL,output
        MOV AH,02H
        INT 21H
        JMP NEXT

L11: ;数字超出循环输出
        SUB BL,0AH
        MOV output,BL
        MOV DL,output
        MOV AH,02H
        INT 21H
        JMP NEXT

L2:     ;L2标志,输出加密结果
        MOV BL,input
        ADD BL,05H
        MOV A,BL
        CMP A,'Z' ;与Z比较
        JG CHARout
        MOV output,BL
        MOV DL,output
        MOV AH,02H
        INT 21H
        JMP NEXT


L3:     ;L2标志,输出加密结果
        MOV BL,input
        ADD BL,05H
        MOV A,BL
        CMP A,'z' ;与z比较
        JG CHARout
        MOV output,BL
        MOV DL,output
        MOV AH,02H
        INT 21H
        JMP NEXT

CHARout: ;字符超出循环输出
        SUB BL,1AH
        MOV output,BL
        MOV DL,output
        MOV AH,02H
        INT 21H
        JMP NEXT

NEXT: ;继续程序
        MOV DL,0DH  ;回车
        MOV AH,02H
        INT 21H
        MOV DL,0AH  ;换行
        MOV AH,02H
        INT 21H

        LEA DX,str3 ;输出提示字符串3
        MOV AH,09
        INT 21H
        
        MOV AH,1 ;接收一个字符
        INT 21H
        MOV BH,AL

        MOV DL,0DH  ;回车
        MOV AH,02H
        INT 21H
        MOV DL,0AH  ;换行
        MOV AH,02H
        INT 21H

        CMP BH,'#' ;判断用户输入的字符
        JE BEGIN
        JMP DOWN
    
DOWN:
    MOV DL,0DH  ;回车
    MOV AH,02H
    INT 21H
    MOV DL,0AH  ;换行
    MOV AH,02H
    INT 21H
    
    LEA DX,str4 ; 程序结束语
    mov ah,09
    INT 21h
    
    MOV AH,4CH ;结束
    INT 21H
CODE ENDS
    END START

Computational results

Konwledge point

  1. the string value need the $ in ending
  2. need to enter before you wrap,if you need “wrap”
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
### Machine Learning Branching Strategy or Implementation Machine learning branching strategies are commonly used in optimization problems, particularly within the context of mixed-integer linear programming (MILP) solvers. These strategies determine which variable to branch on during the branch-and-bound process, aiming to reduce the search space efficiently and find optimal solutions faster. Below is an explanation of the concept and potential implementations. #### Concept of ML-Based Branching Traditional branching methods such as most-fractional branching or pseudocost branching rely on heuristics based on problem structure or historical data. However, machine learning techniques can enhance these strategies by learning patterns from past solving experiences. This approach involves training models using features extracted from nodes in the branch-and-bound tree and predicting which variable would lead to a better reduction in the objective function gap[^1]. #### Implementation Details An implementation of machine learning for branching typically includes the following components: 1. **Feature Extraction**: Features are derived from the current state of the branch-and-bound tree, such as the fractional part of variables, relaxation bounds, and constraint coefficients. 2. **Model Training**: Historical data from previous solves is used to train supervised learning models. Commonly used algorithms include decision trees, random forests, and neural networks. 3. **Prediction and Selection**: During the solving process, the trained model predicts the effectiveness of branching on each candidate variable and selects the one with the highest predicted improvement. Here is an example of how a simple ML-based branching strategy might be implemented in Python using scikit-learn: ```python from sklearn.ensemble import RandomForestClassifier import numpy as np # Example feature extraction function def extract_features(node): # Extract features like fractional part, relaxation bounds, etc. fractional_part = node['variable_values'] - np.floor(node['variable_values']) relaxation_bounds = node['relaxation_bounds'] return np.concatenate([fractional_part, relaxation_bounds]) # Example training data generation def generate_training_data(nodes, best_branches): X = [extract_features(node) for node in nodes] y = best_branches # Labels indicating the best branch for each node return np.array(X), np.array(y) # Train a Random Forest classifier X_train, y_train = generate_training_data(training_nodes, best_branches) model = RandomForestClassifier() model.fit(X_train, y_train) # Use the model to predict the best branching variable def predict_best_branch(node): features = extract_features(node).reshape(1, -1) prediction = model.predict(features) return prediction[0] # Example usage current_node = {...} # Current node in the branch-and-bound tree best_variable_to_branch = predict_best_branch(current_node) ``` #### Integration with Existing Solvers The described ML-based branching strategy can be integrated into existing MILP solvers like CBC[^2]. By replacing or augmenting the default branching rules with predictions from the machine learning model, the solver may achieve improved performance on certain types of problems.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值